1. 深度遍历
function deepCloneObject(obj){
if(typeof obj !== 'object' || obj === null){
return obj;
}
if(obj === {}){
return {};
}
let sourceObj = obj;
let targetObj = {};
for(let key in obj){
targetObj[key] = sourceObj[key];
}
return targetObj;
}
2. 转换为字符串
function deepCloneObject(obj){
return JSON.parse(JSON.stringify(obj));
}
3. 展开运算符
function deepCloneObject(obj){
return {...obj};
}