function isObject(obj) {
const type = typeof obj
return obj !== null && (type == "function" || type == "object")
}
function deepClone(orginObj,map = new WeekMap()) {
if(typeof orginObj == "function") {
return orginObj
}
if(!isObject(orginObj)) {
return orginObj
}
if(map.has(orginObj)) {
return orginObj
}
const targetObj = Array.isArray(orginObj)?[]:{}
map.set(orginObj,targetObj)
const keys = Object.keys(orginObj)
for(let key of keys) {
targetObj[key] = deepClone(orginObj[key],map)
}
return targetObj
}```