手写深拷贝(面试题)
1 function deepClone(obj){ 2 let objClone = Array.isArray(obj) ? [] : {}; 3 if (obj && typeof obj === 'object') { 4 for(let key in obj){ 5 if (obj[key] && typeof obj[key] === 'object'){ 6 objClone[key] = deepClone(obj[key]); 7 }else{ 8 objClone[key] = obj[key] 9 } 10 } 11 } 12 return objClone; 13 }