Merge commit '510d060cb2'
This commit is contained in:
commit
bb3fa62824
1 changed files with 11 additions and 7 deletions
|
|
@ -81,20 +81,24 @@ exports.copyArray = function(array){
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deepCopy = function (obj) {
|
exports.deepCopy = function deepCopy(obj) {
|
||||||
if (typeof obj !== "object" || !obj)
|
if (typeof obj !== "object" || !obj)
|
||||||
return obj;
|
return obj;
|
||||||
|
var copy;
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
copy = [];
|
||||||
|
for (var key = 0; key < obj.length; key++) {
|
||||||
|
copy[key] = deepCopy(obj[key]);
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
var cons = obj.constructor;
|
var cons = obj.constructor;
|
||||||
if (cons === RegExp)
|
if (cons === RegExp)
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
var copy = cons();
|
copy = cons();
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (typeof obj[key] === "object") {
|
copy[key] = deepCopy(obj[key]);
|
||||||
copy[key] = exports.deepCopy(obj[key]);
|
|
||||||
} else {
|
|
||||||
copy[key] = obj[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue