SOURCE

function clone(target, map = new Map()) {
    if(typeof target == "object") {
        // let cloneValue = Array.isArray(target) ? [] : {};
        const isArray = Array.isArray(target);
        let cloneValue = isArray ? [] : {};
        if(map.get(target)) {
            return map.get(target);
        }
        map.set(target, cloneValue);
        // for(const i in target) {
        //     cloneValue[i] = clone(target[i], map);
        // }
        const keys = isArray ? undefined : Object.keys(target);
        While(keys || target, (value, key) => {
            if(keys) {
                key = value;
            }
            cloneValue[key] = clone(target[key], map);
        })

        return cloneValue;
    }else {
        return target;
    }
}

function While(array, callback) {
    let index = -1;
    const len = array.length;
    while(++index < len) {
        callback(array[i], index);
    }
}
console 命令行工具 X clear

                    
>
console