Debounce Function in JavaScript
A utility function that limits how often a function can fire, useful for search input or resize events.
Mã nguồn
1function debounce(fn, delay = 300) {
2 let timeout;
3 return (...args) => {
4 clearTimeout(timeout);
5 timeout = setTimeout(() => fn(...args), delay);
6 };
7}
8