Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created April 23, 2018 08:06
Show Gist options
  • Save wesleybliss/e2382839fce2eee329e826e41da4b91b to your computer and use it in GitHub Desktop.
Save wesleybliss/e2382839fce2eee329e826e41da4b91b to your computer and use it in GitHub Desktop.
Throttle (not debounce) a method - similar to lodash, but simpler
const throttle = (fn, delay) => {
let lastCall = 0
return (...args) => {
const now = (new Date).getTime()
if (now - lastCall < delay) return
lastCall = now
return fn(...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment