无聊写了一个深拷贝办法:
deepCopy(arg){return _deepCopy(arg);
function _deepCopy(params){
let tempResult;
if(params instanceof Array){tempResult=[...params]
tempResult.map((item,index)=>{item = _deepCopy(item,tempResult,index);
})
}else if(params instanceof Object){tempResult={...params}
Object.keys(tempResult).map((key,index)=>{tempResult[key]= _deepCopy(tempResult[key], tempResult,key);
})
}else{
let temp=params
return temp;
}
return tempResult
}
}
}
let s = {
a: {
b: {c: '123',},
d: [{aa: '11'}, {bb: '22'}, {cc: '33',dd:[1,2,3] }],
},
}
let a=this.deepCopy(s)
console.log(a==s)
console.log(a===s)
console.log(a)
console.log(s)
“