// 浅拷贝-扩展运算符 let outObj = { inObj: {a: 1, b: 2} } let newObj = {...outObj} newObj.inObj.a = 2 console.log(outObj) // {inObj: {a: 2, b: 2}} // 浅拷贝-Object.assign() // 深拷贝 const deepClone = (obj) => { if(typeOf obj !== 'object') return let newOBj = obj instanceOf Array ? [] : {} for (let key in obj) { if(typeOf obj[key] === 'object' ){ newObj[key] = deepClone(obj[key]) } else { newObj[key] = obj[key] } } return newObj }