js 深度拷贝递归生成
function deepClone(param){ //判断时间 if(param instanceof date) return new Date(param); //如果普通类型直接返回 if(typeof param !== 'object') return param; //如果是则直接回调当前函数进行分解 let cloneTarget = new param.constructor; for( let key in param){ cloneTarget[key] = deepClone(param[key]); } return cloneTarget; } let obj = { name:'taotao', age:10, address:{ city:'bj', living:{ novers:true, time:10 } } } let newObj = deepClone(obj) console.log(newObj)
只是查找方便的总结