8/23 회고 - debounce.ts (with TypeScript)
·
✨회고
오늘은 어려웠던 debounce 함수에 대해 회고를 해보려고 한다.type Timer = ReturnType | null;const debounce = ) => ReturnType>(fn: T, timeout = 300) => { let timer: Timer = null; const debounced = (...args: Parameters) => { if (timer) clearTimeout(timer); timer = setTimeout(() => { fn(...args); }, timeout); }; debounced.cancel = () => { if (timer) { clearTimeout(timer); timer = null; } ..