深拷贝
function deepClone(obj = {}){ if(typeof obj !== 'object' || obj == null){ // 不是对象和数组 或者 是null return obj } let result if(obj instanceof Array){ result = [] }else{ result = {} } for(let key in obj){ // 保证 key 不是原型上的属性 if(obj.hasOwnProperty(key)){ // 递归 result[key] = deepClone(obj[key]) } } return result }
浙公网安备 33010602011771号