Open
Description
第一种方法
function deepClone(obj){
return JSON.parse(JSON.stringify(obj))
}
第二种方法
function deepClone(obj){
if(typeof obj !== 'object') return obj;
if(obj === null) return null;
if(obj instanceof RegExp){
return new RegExp(obj)
}
if(obj instanceof Date){
return new Date(obj)
}
let newObj = new obj.constructor;
for(let key in obj){
newObj[key] = deepClone(obj[key])
}
return newObj
}
Metadata
Metadata
Assignees
Labels
No labels