forked from svrjs/svrjs
Optimize deepClone function even more
This commit is contained in:
parent
c73ce5d9f7
commit
67d9ae524c
1 changed files with 4 additions and 6 deletions
|
@ -27,12 +27,10 @@ function deepClone(obj) {
|
||||||
_objectsArray.push(obj);
|
_objectsArray.push(obj);
|
||||||
_clonesArray.push(clone);
|
_clonesArray.push(clone);
|
||||||
Object.keys(obj).forEach((key) => {
|
Object.keys(obj).forEach((key) => {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
clone[key] =
|
||||||
clone[key] =
|
typeof obj[key] !== "object" || obj[key] === null
|
||||||
typeof obj[key] !== "object" || obj[key] === null
|
? obj[key]
|
||||||
? obj[key]
|
: recurse(obj[key], _objectsArray, _clonesArray);
|
||||||
: recurse(obj[key], _objectsArray, _clonesArray);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
|
|
Reference in a new issue