Skip to content

Instantly share code, notes, and snippets.

@JoeSz
Last active September 28, 2016 10:20
Show Gist options
  • Save JoeSz/b8c5e118fdc0c9adc325c1fc19679043 to your computer and use it in GitHub Desktop.
Save JoeSz/b8c5e118fdc0c9adc325c1fc19679043 to your computer and use it in GitHub Desktop.
JavaScript Throttle
// 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