SOURCE

function debounce(func, wait) {
    let timer;
    return function (){
        let context = this;
        if (timer) {
            clearTimeout(timer);
            timer = null;
        };
        timer = setTimeout(function(){
            func.apply(context, arguments);
            clearTimeout(timer);
            timer = null;
        }, wait);
    }
}
let n = 0;
function test() {
    n++;
    console.log(n);
}
let count = 0;

const debounceTestFn = debounce(test, 1000);
let timer = setInterval(function(){
    debounceTestFn();
    count++;
    if (count === 10) {
        clearInterval(timer);
        timer = null;
    }
},100)
console 命令行工具 X clear

                    
>
console