frontend-challenges
frontend-challenges copied to clipboard
20 - throttle - javascript
index.js
export function throttle(cb, delay = 250) {
let shouldInvoke = true;
return (...args) => {
if (shouldInvoke) {
shouldInvoke = false;
cb.call(this, ...args);
setTimeout(() => {
shouldInvoke = true;
}, delay);
}
};
}