递归深拷贝
function deepClone(obj) {
let result = Array.isArray(obj) ? [] : {};
// if (typeof obj != 'object') {
// // 这里不能直接返回obj,不然就是浅拷贝的性质
// return result = obj
// }
if (obj && typeof result == "object") {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] == "object") {
result[key] = deepClone(obj[key]);
} else {
result[key] = obj[key]
}
}
}
}
return result;
}