Skip to content

Instantly share code, notes, and snippets.

@ishwarrimal
Created August 24, 2020 10:31
Show Gist options
  • Save ishwarrimal/d10a196c5ceafc52742e55c436f3423c to your computer and use it in GitHub Desktop.
Save ishwarrimal/d10a196c5ceafc52742e55c436f3423c to your computer and use it in GitHub Desktop.
Simple implementation of throttle in JS
export function throttle(callback, delay, options = {}) {
let flag = true
return () => {
if (flag) {
flag = false
setTimeout(() => {
callback(options)
flag = true
}, delay)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment