SOURCE

function deepClone(obj = {}){
    if(typeof obj !== 'object' || obj == null){
        return obj
    }

    let result
    if(obj instanceof Array){
        result = []
    }else{
        result = {}
    }
    
    for(let key in obj){
        if(obj.hasOwnProperty(key)){
            result[key] = deepClone(obj[key])
        }
    }

    return result
}

let chai = {
    name: 'chai',
    age:12,
    job:{
        to:'coding'
    }
}

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

                    
>
console