1.JSON对象
let deepCloneObj = JSON.parse(JSON.stringify(obj))
2.递归函数
function cloneDeep (source) {
if (!this.isObject(source)) return source; // 非对象返回自身
let target = Array.isArray(source) ? [] : {}
for (let key in source) {
if (source.hasOwnProperty(key)) {
if (this.isObject(source[key])) {
target[key] = this.cloneDeep(source[key]) // 注意这里
} else {
target[key] = source[key]
}
}
}
return target
}