SOURCE

function deepClone(obj){
  function isObj(o){
     return (typeof o === 'object' || typeof o === 'function') && o !== null
  }
  
  if(!isObj(obj)) {throw new Error('不是对象')}
  
  var isArray = Array.isArray(obj)
  var newObj  = isArray? [...obj]: {...obj}
  Object.getOwnPropertyNames(newObj).forEach( key =>{
    newObj[key] = isObj(obj[key]) ? deepClone(obj[key]) : obj[key]
  })
  
  return newObj
}

let obj = {
  a: [1, 2, 3],
  b: {
    c: 2,
    d: 3
  }
}
let newObj = deepClone(obj)
newObj.b.c = 1
console.log(obj.b.c) // 2
console 命令行工具 X clear

                    
>
console