InterviewMap / CS-Interview-Knowledge-Map

Build the best interview map. The current content includes JS, network, browser related, performance optimization, security, framework, Git, data structure, algorithm, etc.
https://yuchengkai.cn/docs/frontend/
18.3k stars 2.57k forks source link

complement descriptions of deep clone #142

Closed zoux closed 6 years ago

zoux commented 6 years ago

JSON.parse( JSON.stringify() ) 实现深拷贝,除了文中提到的局限性外,还存在忽略 Symbol 的情况。

此 PR 弥补了以上内容的缺失。

以下是 demo code,可以在控制台检测一下:

let a = { age: undefined, sex: Symbol('male'), jobs: function() {}, name: 'yck' } let b = JSON.parse(JSON.stringify(a)) console.log(b)