if( typeof obj[attr] === 'object'){ newObj[attr] = deepClone(obj[attr]);}
function deepClone(obj){
let newObj = obj.push?[]:{}; //若是obj有push方法则 定义newObj为数组,不然为对象。
for(let attr in obj){
if(typeof obj[attr] === 'object'){
newObj[attr] = deepClone(obj[attr]);
}else{
newObj[attr] = obj[attr];
}
}
return newObj;
}
复制代码