1
2
3
4
5
6
7
8
9
10
11
12
13
14
| export const debounce = function(func, wait) {
| let startTime = Date.now();
| let timer;
|
| return (...args) => {
| if (Date.now() - startTime < wait && timer) {
| clearTimeout(timer);
| }
| timer = setTimeout(() => {
| func(...args);
| }, wait);
| startTime = Date.now();
| }
| }
|
|