SOURCE

function lightCopy(obj){
    let newObj = obj.constructor()
    for(let i in obj){
        if(obj.hasOwnProperty(i)){
            newObj[i] = obj[i]
        }
    }
    return newObj
}
let obj = {
    name: 'lis',
    age: 18,
    say(){
        console.log(this.age)
    }
}
console.log(lightCopy(obj))

function deepClone(obj){
    
    if(obj === null) return null
    if(typeof obj !== 'object')   return obj
    if(obj instanceof Date) return new Date(obj)
    if(obj instanceof RegExp) return new RegExp(obj)
    let newObj = new obj.constructor
    for(let i in obj){
        if(obj.hasOwnProperty(i)){
            newObj[i] = deepClone(obj[i])
        }
    }
    return newObj
}
console.log(deepClone(obj))
console 命令行工具 X clear

                    
>
console