没有考虑到数组得引用 没有进行深拷贝得时候引用一直在点击树结构再更改数组中得值 失效,刚开始考虑到这个 使用concat但是这个只能对一级进行深拷贝所以是无效得 关于深拷贝处理方式
let colors=['red','green','blue',['football','basketball','volleyball']];
let colors2=Object.assign([],colors);
没有function时候可以使用上图所示
当有function时
function _deepClone(source) {
let target;
if (typeof source === 'object') {
target = Array.isArray(source) ? [] : {}
for (let key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] !== 'object') {
target[key] = source[key]
} else {
target[key] = _deepClone(source[key])
}
}
}
} else {
target = source
}
return target
}```