# 防抖、节流

点我查看、两者的全面分析

// 节流
function throttle(fn, interval) {
    let flag = true;
    return function(...args) {
        if (flag){
            flag = false;
            setTimeout(() => {
                fn.apply(this, args);
                flag = true;
            }, interval);
        }
    }
}
// 防抖
function debounce(fn, interval) {
    let timer = null;
    return function (...args) {
        if(timer) clearTimeout(timer);
        timer = setTimeout(() => {
            fn.apply(this, args);
        }, interval);
    }
}