1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| const debounce2 = (function () { let timer = null; let flag = true; return function (func, delay = 1000) { if (flag) { flag = false; func.call(); return; } if (timer) { clearTimeout(timer); } timer = setTimeout(() => { flag = true; func.call(); }, delay); }; })();
export default { debounce, debounce2, };
|