SOURCE

const debounce = (fn, delay = 1000) => {
    let timer = null;

    return () => {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            fn();
        }, delay);
    }
}

const throttle = (fn, delay = 1000) => {
    let runState = true;

    return () => {
        if (!runState) {
            return;
        }
        runState = false;
        setTimeout(() => {
            fn();
            runState = true;
        }, delay)
    }
};
console 命令行工具 X clear

                    
>
console