SOURCE

function clone(data){
    if(typeof data !='object'){
        return data //基本数据类型
    }else if(data instanceof Array){
        return data.map(item=>clone(item)) //数组递归
    }else if(data.constructor === Object){
        let res = {}
        for(let key in data){
            res[key] = clone(data[key])
        }
        return res //json
    }else{
        return new data.constructor(data); //系统对象,自定义对象
    }
}

let a = [{a:10,b:20},{c:30,d:40}]

let b = clone(a)
b[0].a++
console.log(a)
console.log(b)
console 命令行工具 X clear

                    
>
console