var obj = {
name : "bac",
age : 123,
card : ['visa','master'],
wife : {
name : 'uio',
son : {
name : 'qqq'
}
}
}
var obj1 = {};
function deepClone(origin,target){
var target = target || {},
toStr = Object.prototype.toString,
arrStr = "[object Array]";
for(var prop in origin){
if( origin.hasOwnProperty(prop)){
if(origin[prop] !== "null"
&& typeof(origin[prop]) == 'object'){
if(toStr.call(origin[prop]) == arrStr){
target[prop] = [];
}else{
target[prop] = {};
}
deepClone(origin[prop],target[prop]);
}else{
target[prop] = origin[prop];
}
}
}
return target;
}
JS实现深拷贝
最新推荐文章于 2022-11-01 16:14:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)