function deepClone(obj={}){
if(typeof obj !== 'object' || obj == null){
return
}
let result
if(Array.isArray(obj)){
result = []
} else {
result = {}
}
for (const key in obj){
if(obj.hasOwnProperty(key)){
result[key] = deepClone(obj[key])
}
}
return result
}
手写深拷贝
最新推荐文章于 2024-11-14 15:33:48 发布