function deepCopy(obj,cache){
if(cache===void 0) cache=[]
if(obj===null||typeof obj !== "object") return obj
let hit=cache.filter(i=>i.origin===obj)[0]
if(hit) return hit.copy
let copy=Array.isArray(obj)?[]:{}
cache.push({
origin:obj,
copy:copy
})
Object.keys(obj).forEach(i=>{
copy[i]=deepCopy(obj[i],cache)
})
return copy
}
对象或数组的深拷贝
最新推荐文章于 2025-11-30 09:20:25 发布

159

被折叠的 条评论
为什么被折叠?



