var obj1 = [{
name: '臧三',
childs: ['小明', '小芳'],
fn: function() {},
age: undefined
}]
var obj2 = extend2(obj1)
console.log( obj2)
function extend2(data){
if (typeof data === 'object' && data){
let val = typeof data.length === 'number' ? [] :{}
for(let temp in data){
val[temp] = extend2(data[temp])
}
return val
}else {
return data
}
}
递归实现深拷贝
最新推荐文章于 2023-12-31 21:20:14 发布