SOURCE

// 防抖
function debounce(fn, delay) {
    let timeout = null;
    return function() {
        clearTimeout(timeout);
        timeout = setTimeout(() => {
            fn.apply(this, arguments)
        }, delay)
    }
}

// 节流
function throttle(fn, delay) {
    let run = true; // 开关
    return function() {
        if (!run) {
            return
        }
        run = false
        setTimeout(() => {
            fn.apply(this, arguments);
            run = true;
        }, delay);
    }
}

// throttle(printPos(), 1000);



function throttle(fn, delay) {
    let flag = true;
    return () => {
        if (!flag) {
            return;
        }
        flag = false;
        setTimeout(() => {
            fn.apply(this, fn);
            flag = true;
        }, delay);
    }
}
console 命令行工具 X clear

                    
>
console