# 深拷贝

点我查看深拷贝的全面分析

简易面试版!!

function deepClone(target) {
    // is Object???
    if (typeof target == "object") {
        // array or object
        const result = Array.isArray(target) ? [] : {}
        for (let key in target) {
            if (target.hasOwnProperty(key)) {
                // 引用类型需要再次递归
                result[key] = typeof target[key] == "object" ? deepClone(target[key]) : target[key]
            }
        }
        return result
    }
    return target
}