复制js对象方法(详解)
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:CSSCommonJS.DeepCopy=function(json){if(typeofjson=='number'||...
复制代码 代码如下:
CSSCommonJS.DeepCopy = function (json) {
if (typeof json == 'number' || typeof json == 'string' || typeof json == 'boolean') {
return json;
} else if (typeof json == 'object') {
if (json instanceof Array) {
var newArr = [], i, len = json.length;
for (i = 0; i < len; i++) {
newArr[i] = arguments.callee(json[i]);
}
return newArr;
} else {
var newObj = {};
for (var name in json) {
newObj[name] = arguments.callee(json[name]);
}
return newObj;
}
}
}