SOURCE

function deepCopy(target, hash = new WeakMap()) {
  if (typeof target === 'object' && target !== null) {
    if(hash.has(target)) {
      return hash.get(target);
    }
    let o = target instanceof Array ? [] : {};
  	hash.set(o, target);
    for (var key in target) {
        if(Object.prototype.hasOwnProperty.call(target, key)) {
            if(typeof target[key] === 'object') {
                o[key] = deepCopy(target[key], hash);
            } else {
                o[key] = target[key];
            }
        }
    }
    return o;
  } else {
    return target;
  }
}


var a = {
    name: "muyiy",
    book: {
        title: "You Don't Know JS",
        price: "45"
    },
    a1: undefined,
    a2: null,
    a3: 123
};

console.log(JSON.stringify(a));
console.log(JSON.stringify(deepCopy(a)));
console 命令行工具 X clear

                    
>
console