web
9 天以前 81a0e26f1ba5fd0b95381ee902caa1579a8ec043
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//防抖(立即执行)
export function debounce(func, wait, immediate) {
    let timeout;
    return function(...args) {
        const context = this;
        const later = () => {
            timeout = null;
            if (!immediate) func.apply(context, args);
        };
        const callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
    };
}