function deepClone(obj = {}){
// 判断拷贝对象的数据类型
if(typeof obj !== 'object' || obj == null){
return obj
}
let result
if(obj instanceof Array){
result = []
} else {
result = {}
}
for(let key in obj){
//判断key的属性是否是自有属性
if(obj.hasOwnProperty(key)){
//使用递归
result[key] = deepClone(obj[key])
}
}
return result
}
1360

被折叠的 条评论
为什么被折叠?



