SOURCE

function debounce(func, wait = 500) {
    let timeout;
    return function () {
        let context = this;
        let args = arguments;
        if (timeout) clearTimeout(timeout);      
        timeout = setTimeout(() => {
            func.apply(context, args)
        }, wait);
    }
}

function throttle(func, wait = 1000) {
    let previous = 0;
    return function() {
        let context = this;
        let args = arguments;
        let now = Date.now();
        if (now - previous > wait) {
            func.apply(context, args);
            previous = now;
        }
    }
}
console 命令行工具 X clear

                    
>
console