SOURCE

function throttle(fn, delay = 300) {
    let timer;
    return function(...rest) {
        if (timer) {
            return;
        }
        timer = setTimeout(() => {
            fn.apply(this, rest);
            timer = null;
        }, delay);
    };
}

const task = () => { console.log('run task') }
const throttleTask = throttle(task, 1000)
throttleTask()
throttleTask()
throttleTask()
setTimeout(() => {
    throttleTask();
}, 2000);
console 命令行工具 X clear

                    
>
console