- 浅拷贝
// 第一层为深拷贝 Object.assign() Array.prototype.slice() 扩展运算符 ...
- 深拷贝
JSON.parse(JSON.stringify())
递归函数
function cloneObject(obj) { var newObj = {} //如果不是引用类型,直接返回 if (typeof obj !== 'object') { return obj } //如果是引用类型,遍历属性 else { for (var attr in obj) { //如果某个属性还是引用类型,递归调用 newObj[attr] = cloneObject(obj[attr]) } } return newObj }
.