SOURCE

// 基本数据类型都对应, null 为 object
// let typeObj = {
    
// }
function clone(tar) {
    let u
    let TYPE = typeof tar
    switch (TYPE) {
        case 'string':
            u = tar+'';
            break;
        case 'number':
            u = tar-0;
            break;
        case 'boolean':
            u = tar;
            break;
        case 'object':
            if(tar === null) {
                u = null
            } else {
                if (Object.prototype.toString.call(tar).slice(8,-1) === 'Array') {
                    u = []
                    for(let i=0; i < tar.length; i++) {
                        u.push(clone(tar[i]))
                    }
                } else {
                    u = {}
                    for(let key in tar) {
                        u[key] = clone(tar[key])
                    }
                }
            }
            break;
        default:
            break;
    }
    return u
}

console.log(clone(true))
console.log(clone(null))
console.log(clone([1,2,3]))
console.log(clone({a: 11, b: 'obj'}))
console.log(Object.prototype.toString.call([]).slice(8,-1))
console 命令行工具 X clear

                    
>
console