切换主题
字数
58 字
阅读时间
1 分钟
js
let alex = {
name:'Alex',
age:20,
family:{
mother:1,
father:1,
}
}
function deepClone(obj){
if(obj<mark>=null||typeof (obj) !</mark> 'object'){
return obj;
}else{
let copy = Array.isArray(obj)?[]:{};
for(let key in obj){
if(obj.hasOwnProperty(key)){
copy[key] = deepClone(obj[key])
}
}
return copy;
}
}
let bob = deepClone(alex)
alex.age = 211
console.log(bob)
console.log(alex)
贡献者
sunchengzhi