递归:自己调用自己
// 计算累加 function fun(n){ if (n === 1){ return 1 } else { return n + fun(n - 1) } } let res = fun(3) console.log(res) // 6
// 深拷贝 function copy(obj){ let newObj = {} for(let i in obj){ if(obj[i] instanceof Object){ newObj[i] = copy(obj[i]) }else{ newObj[i] = obj[i] } } return newObj }
当对象里面的值还是对象的时候,利用深拷贝就可以实现复制了