递归
let deepClone = function(o){
let result = Array.isArray(o)?[]:{}
for(let k in o ){
if(o[k] instanceof Array||o[k] instanceof Object){
result[k] = deepClone(o[k])
}else{
result[k]=o[k]
}
}
return result
}
JSON
let deepClone = function(o){
return JSON.parse(JSON.stringify(o))
}
网友评论