写一个深拷贝函数
-
使用 JSON.stringify 和 parse 这类只能适合数据结构简单的,不能循环引用的,没有function的
-
普通深拷贝
-
只考虑 Object Array
-
无法转换 Map Set 和 循环引用
function cloneDeep(obj: any) { if (typeof obj !== 'object' || !obj) return obj const result = obj instanceof Array ? [] : { } for (let key in obj) { if (obj.hasOwnProperty(key)) { result[key] = cloneDeep(obj[key]) // 递归调用 } } return result } // 不支持的场景 const a:
-
1120



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



