We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The text was updated successfully, but these errors were encountered:
把源对象所有的本地属性一起复制到目标对象上。有时候这种操作也被称为“混入”(mixin),因为目标对象通过混入源对象的属性得到了增强。
深拷贝和浅拷贝主要针对于引用类型数据,因为基本数据类型赋值后,改变新数据,不会影响到原来的数据;而引用数据类型赋值后,改变新数据,将会影响到原来的数据,此时应该使用深拷贝和浅拷贝定义出一个跟原数据一样但互不影响的数据。 注意:赋值操作和深拷贝浅拷贝不是一回事。
let test = {name: 'test'} let data = { a: '123', b: 123, c: true, d: [43, 2], e: undefined, f: null, g: function() { console.log("g"); }, h: new Set([3, 2, null]), i: Symbol("fsd"), j: test, k: new Map([ ["name", "张三"], ["title", "Author"] ]) }; <!-- 比较好的方式 --> function deepCopy(obj){ if(typeof obj === 'function'){ throw new TypeError('请传入正确的数据类型格式') } try { let data = JSON.stringify(obj) let newData = JSON.parse(data) return newData } catch(e) { console.log(e) } }
Sorry, something went wrong.
No branches or pull requests
题目:合并对象有哪些方法?介绍一下深拷贝和浅拷贝
The text was updated successfully, but these errors were encountered: