function deepCopy (source) {
var result;
if(Object.prototype.toString.call(source) === '[object Date]') {
result = new Date();
result.setTime(source.getTime());
} else if(Object.prototype.toString.call(source) === '[object Array]') {
result = [];
for(var i = 0, len = source.length; i < len; i++) {
result.push(arguments.callee(source[i]))
}
} else if(Object.prototype.toString.call(source) === '[object Object]') {
result = {};
for(var key in source) {
if(source.hasOwnProperty(key)) {
result[key] = arguments.callee(source[key]);
}
}
} else {
return source;
}
return result;
};
js对象深拷贝
最新推荐文章于 2023-02-24 12:13:26 发布