防抖

function debound(fn, wait) {
    let time;
    return function(...args) {
        if(time) {
            clearTimeOut(time)
        } 

        time = setTimeOut(() => {
            fn.apply(this, args)
        }, wait)
    }
}

节流

节流的意思 是在单位时间内只执行一次

function throttle(fn, wait) {
    let time = null;

    return function(...args) {
        if(!time) {
            // 当前没有事件
            time = setTimeOut(() => {
                time = null;
                fn.apply(this, args)
            }, wait)
        }
    }
}

promise

参考链接