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);
| };
| }
|
|