Last active
September 28, 2016 10:20
-
-
Save JoeSz/b8c5e118fdc0c9adc325c1fc19679043 to your computer and use it in GitHub Desktop.
JavaScript Throttle
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
// Returns a function, that, when invoked, will only be triggered at most once | |
// during a given window of time. | |
// Source: https://gist.github.com/killersean/6742f98122d1207cf3bd | |
function throttle(callback, limit, callbackArgs) { | |
var wait = false; | |
return function() { | |
if (wait) { | |
return; | |
} | |
callback.call(callbackArgs); | |
wait = true; | |
setTimeout(function() { | |
wait = false; | |
}, limit); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment