SOURCE

var beforObj = {
    name:'张三',
    sex:'男',
    age:'18',
    body:{
        height: '180cm',
        weight: '70kg'
    },
    arry: [1,2,3,4,5,6,7,8,9,10]
}

function deepClone(obj) {
    var newObj = null
    if(typeof(obj) == 'object' && typeof(obj) !== null){
        newObj = obj instanceof Array ? [] : {}
        for(var i in obj){
            newObj[i] = deepClone(obj[i])
        }
    } else {
        newObj = obj
    }
    return newObj
}
var afterObj = deepClone(beforObj)
afterObj.age = 30
console.log(afterObj)
console.log(beforObj)
console 命令行工具 X clear

                    
>
console