节流与防抖

节流

const throttle = (func, wait) => {
    let timer;
    return () => {
        if (timer) {
            return;
        }
        timer = setTimeout(() => {
            func();
            timer = null;
        }, wait);
    };
};

防抖

const debounce = (func, wait) => {
    let timer;
    return () => {
        clearTimeout(timer);
        timer = setTimeout(func, wait);
    };
};
Last Updated:
Contributors: af, zhangfei