SOURCE

var obj = {
   a: 1,
   b: 2,
   c: {
       fun: function (){
           console.log('傻逼老板,真抠')
       }
   }
}

// 方式一:使用系统自带方法实现

var newObj = JSON.parse(JSON.stringify(obj))
var arr = [1,2,34,56,8]

// console.log(obj,newObj)

// 方拾二:使用传统封装函数的方式实现

function deepClone(obj){
    // 第一步:申明变量存储拷贝结果
    var newObj1 = null
//    第二步:判断传参的类型
      if(typeof obj !== Object){
          return obj
      }else if(typeof obj === Object && obj !== null){
        //   判断最终接受复制对象的类型
          newObj1 = obj instanceof Array? [] : {}
          for(var key in obj){
              if(typeof obj[key] == Object){
                  deepClone(obj[key])
              }else{
                  newObj1[key] = obj[key]
              }
          }
      }
      return newObj1
}

console.log(deepClone(obj))
console.log(deepClone(arr))
console 命令行工具 X clear

                    
>
console