SOURCE

function deepClone(obj) {
    const newObj = obj.constructor === Array  ? [] : {};
    for(let key in obj) {
        if(obj.hasOwnProperty(key)) {
            if(typeof obj[key] === "object") {
                newObj[key] = deepClone(obj[key])
            }else{
                newObj[key] = obj[key]
            }
        }
    }
    return newObj;
}

let obj = {
    name: 'Hanna',
    age: 22,
    num: {
        num1: 1,
        num2: 2
    },
    arr: [1,3,4],
    message: function() {
        console.log(1111)
    }
}
let objCopy = deepClone(obj)

console.log(objCopy.message())
console 命令行工具 X clear

                    
>
console