Created
April 23, 2018 08:06
-
-
Save wesleybliss/e2382839fce2eee329e826e41da4b91b to your computer and use it in GitHub Desktop.
Throttle (not debounce) a method - similar to lodash, but simpler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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