深拷贝
function deepClone(startObj, endObj) { let obj = endObj || {}; for (let i in startObj) { if (typeof startObj[i] === 'object') { obj[i] = startObj[i].constructor === Array ? [] : {}; deepClone(startObj[i], obj[i]) } else { obj[i] = startObj[i]; } } return obj; }
方式1 递归 deepClone
方式2 let b = JSON.parse(JSON.stringify(a))