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)
标签:return,递归,param,js,deepClone,let,key,拷贝,cloneTarget From: https://www.cnblogs.com/qutao125/p/16921535.html