function deeClone(origin, target) {
var target = target || {},
toStr = Object.prototype.toString,
arrType = '[object Array]';
for(var key in origin) {
if(origin.hasOwnProperty(key)) {
if(typeof(origin[key]) === 'object' && origin[key] !== null) {
target[key] = toStr.call(origin[key]) === arrType ? [] : {};
deepClone(origin[key], target[key]);
} else {
target[key] = origin[key];
}
}
}
return target;
}
网友评论