深拷贝函数
// 深拷贝
function deepClone(obj){
if(obj ===null){
return obj;
}
if(obj instanceof Date){
return new Date(obj);
}
if(obj instanceof RegExp){
return new RegExp(obj);
}
if(typeof obj !='object'){
return obj;
}
let res={};
for(let i in obj){
if(obj.hasOwnProperty(i)){
res[i]=deepClone(obj[i]);
}
}
return res;
}
欢迎交流