Skip to content

Instantly share code, notes, and snippets.

@nefarioustim
Created June 28, 2011 16:01
Show Gist options
  • Save nefarioustim/1051475 to your computer and use it in GitHub Desktop.
Save nefarioustim/1051475 to your computer and use it in GitHub Desktop.
Throttle a function
function throttle(fn, delay) {
var timer = null;
return function () {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment