SOURCE

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

const task = () => { console.log('run task') }
const debounceTask = debounce(task, 1000)
debounceTask()
debounceTask()
debounceTask()
console 命令行工具 X clear

                    
>
console