function deepClone(obj){
function isObject(o){
return (typeof o === 'object' || typeof o === 'function') && o !== null
}
if(!isObject(obj)){return obj}
let newObj = Array.isArray(obj) ? [] : {}
for(key in obj){
if(obj.hasOwnProperty(key)){
newObj[key] = isObject(obj[key]) ? deepClone(obj[key]) : obj[key]
}
}
return newObj
}
hasOwnProperty 判断该属性是否为对象的自有属性
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/279775.html