web
2025-04-29 51eeb5d0acba9b783e5c939c1fad4beffcaef8b2
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);
    };
}