Skip to content

Instantly share code, notes, and snippets.

@LucasIron
LucasIron / debounce_throttle.js
Last active January 21, 2021 19:04
Debounce & Throttle
debounce = (delay, cancel) => (listener, wait) => {
let delayId
return function(...args) {
cancel(delayId)
return delayId = delay(() => listener.apply(this, args), wait)
}
}
debounceTimeout = debounce(setTimeout, clearTimeout)
debounceAnimationFrame = debounce(requestAnimationFrame, cancelAnimationFrame)