Last active
May 10, 2017 20:22
-
-
Save RSNara/05be018794f28c7a9715ad7401ded10b to your computer and use it in GitHub Desktop.
Throttle in JS
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
function throttle(fn) { | |
let token = null; | |
return function thunk() { | |
if (token) { | |
return; | |
} | |
token = requestAnimationFrame(() => { | |
token = null; | |
thunk.apply(this, arguments); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment