递归
copy(obj) {
let newObj = {};
for (let i in obj) {
if (obj[i] instanceof Object) {
newObj[i] = this.copy(obj[i])
} else {
newObj[i] = obj[i]
}
}
return newObj
}
转JSON深拷贝
copy(obj) {
let old = JSON.stringify(obj)
let newObj = JSON.parse(old)
return newObj
}
--------------------------或者下面这样-----------------------------
copy(obj) {
let newObj = JSON.parse(JSON.stringify(obj))
return newObj
}