Description
Throttle is the act of only letting the user take an action once in a given period of time.
?
Reach for when
You want to prevent duplicate actions on things like buttons.
Code
function throttle(fn, delay) {
let executeAt = Date.now()
return function (...args) {
const now = Date.now()
if (executeAt <= now) {
executeAt = now
return fn.apply(this, args)
}
};
}