function deepClone(target,map = new WeakMap) {
if(typeof target !== 'object' | typeof target == null) return target
if(map.has(target)) return map.get(target)
const clonedTarget = Array.isArray(target) ? [] : {}
map.set(target,clonedTarget) //先占位,后续在遍历的时候会直接通过索引填值
for (const key in target) {
if (target.hasOwnProperty(key)) {
// 递归调用
clonedTarget[key] = deepClone(target[key],map)
}
}
return clonedTarget
}