js 深度拷贝
作者:互联网
1. 思路
对一个对象进行深度拷贝,就是要把这整个树都复制过来
2. 代码
function deepClone(obj){
if(obj === null)
return;
let tmp = obj.push? [] : {};
for(attr in obj){ // attr这个命名好
if(typeof obj[attr] == 'object')
tmp[attr] = deepClone(obj[attr])
else
tmp[attr] = obj[attr]
}
return tmp;
}
标签:tmp,obj,attr,js,deepClone,深度,return,拷贝 来源: https://www.cnblogs.com/the-one/p/15862211.html