Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit 706ab12

Browse files
author
rsavian
committed
Util - Fix issue with deletePropertyFromObject.
1 parent 6ad6364 commit 706ab12

File tree

2 files changed

+34
-68
lines changed

2 files changed

+34
-68
lines changed

‎js/util/Util.js‎

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,20 @@
6464
Util.deletePropertyFromObject = function (object, value) {
6565
// If properties is not an array then make it an array object.
6666
var list = (value instanceof Array) ? value : [value];
67-
// Loop through the object properties.
68-
for (var key in object) {
69-
// If the key is a property and not function.
70-
if (object.hasOwnProperty(key)) {
71-
var value_1 = object[key];
72-
// If the property is an Array.
73-
if (value_1 instanceof Array) {
74-
// Loop through the Array and call the Util.deletePropertyFromObject method on each object in the array.
75-
var array = value_1;
76-
for (var index in array) {
77-
// Recursive function call.
78-
Util.deletePropertyFromObject(array[index], list);
79-
}
80-
}
81-
else if (value_1 instanceof Object) {
82-
Util.deletePropertyFromObject(value_1, list);
83-
}
84-
else {
85-
// Loop through the list of property name.
86-
for (var listIndex in list) {
87-
// If the key(property name) equals the property name in the list array.
88-
if (key === list[listIndex]) {
89-
// Delete the property from the object.
90-
delete object[key];
91-
}
92-
}
93-
}
67+
Object
68+
.keys(object)
69+
.forEach(function (key) {
70+
var value = object[key];
71+
if (list.includes(key) === true) {
72+
delete object[key];
9473
}
95-
}
74+
else if (value instanceof Array) {
75+
value.forEach(function (item) { return Util.deletePropertyFromObject(item, list); });
76+
}
77+
else if (value instanceof Object) {
78+
Util.deletePropertyFromObject(value, list);
79+
}
80+
});
9681
return object;
9782
};
9883
/**
@@ -276,24 +261,24 @@
276261
* @static
277262
* @example
278263
*
279-
class Flies {
264+
class Flies {
280265
fly() {
281266
alert('Is it a bird? Is it a plane?');
282267
}
283268
}
284269
285-
class Climbs {
270+
class Climbs {
286271
climb() {
287272
alert('My spider-sense is tingling.');
288273
}
289274
}
290275
291-
class HorseflyWoman implements Climbs, Flies {
276+
class HorseflyWoman implements Climbs, Flies {
292277
climb: () => void;
293278
fly: () => void;
294279
}
295280
296-
Util.applyMixins(HorseflyWoman, [Climbs, Flies]);
281+
Util.applyMixins(HorseflyWoman, [Climbs, Flies]);
297282
*/
298283
Util.applyMixins = function (derivedCtor, baseCtors) {
299284
baseCtors.forEach(function (baseCtor) {

‎ts/util/Util.ts‎

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,49 +69,30 @@ class Util
6969
*
7070
* // { name: 'Robert' }
7171
*/
72-
public static deletePropertyFromObject(object:any, value:any):any
72+
public static deletePropertyFromObject(object:any, value:string|Array<string>):any
7373
{
7474
// If properties is not an array then make it an array object.
7575
const list:any = (value instanceof Array) ? value : [value];
7676

77-
// Loop through the object properties.
78-
for (let key in object)
79-
{
80-
// If the key is a property and not function.
81-
if (object.hasOwnProperty(key))
77+
Object
78+
.keys(object)
79+
.forEach(key =>
8280
{
83-
let value:any = object[key];
84-
// If the property is an Array.
85-
if (valueinstanceofArray)
81+
const value:any = object[key];
82+
83+
if (list.includes(key)===true)
8684
{
87-
// Loop through the Array and call the Util.deletePropertyFromObject method on each object in the array.
88-
let array:Array<any> = value;
89-
for (let index in array)
90-
{
91-
// Recursive function call.
92-
Util.deletePropertyFromObject(array[index], list);
93-
}
85+
delete object[key];
9486
}
95-
else if (value instanceof Object)
87+
else if (value instanceof Array)
9688
{
97-
Util.deletePropertyFromObject(value, list);
89+
value.forEach(item=>Util.deletePropertyFromObject(item, list));
9890
}
99-
else
91+
elseif(valueinstanceofObject)
10092
{
101-
// Loop through the list of property name.
102-
for (let listIndex in list)
103-
{
104-
// If the key(property name) equals the property name in the list array.
105-
if (key === list[listIndex])
106-
{
107-
// Delete the property from the object.
108-
delete object[key];
109-
}
110-
}
111-
93+
Util.deletePropertyFromObject(value, list);
11294
}
113-
}
114-
}
95+
});
11596

11697
return object;
11798
}
@@ -337,24 +318,24 @@ class Util
337318
* @static
338319
* @example
339320
*
340-
class Flies {
321+
class Flies {
341322
fly() {
342323
alert('Is it a bird? Is it a plane?');
343324
}
344325
}
345326
346-
class Climbs {
327+
class Climbs {
347328
climb() {
348329
alert('My spider-sense is tingling.');
349330
}
350331
}
351332
352-
class HorseflyWoman implements Climbs, Flies {
333+
class HorseflyWoman implements Climbs, Flies {
353334
climb: () => void;
354335
fly: () => void;
355336
}
356337
357-
Util.applyMixins(HorseflyWoman, [Climbs, Flies]);
338+
Util.applyMixins(HorseflyWoman, [Climbs, Flies]);
358339
*/
359340
public static applyMixins(derivedCtor: any, baseCtors: any[]):void
360341
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /