一 价绍传统深拷贝方案👇
1. 使用 JSON.parse(JSON.stringify(obj)) 👈JOSN数据推荐
(缺点:容易丢数据,比如函数/Set/Date/undefined/Symbol等)
2.自己写遍历方法
(缺点:需要手写这年头谁手写啊,还要处理各种数据类型,需要严谨)
3.使用第三方库比如lodash/radash 👈推荐
(缺点:增加打包体积兼容性等)
一 主角 现代深拷贝structuredClone👇
const dataInfos= {
set: new Set([1, 3, 3]),
map: new Map([[1, 2]]),
regex: /sky/,
deep: { fiels: [ new File(Blob,'test.json') ] },
error: new Error('Hello!')
callback:()=>{}
}
dataInfos.childrenDataInfos= dataInfos
const clonedSink = structuredClone(dataInfos)

1037

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



