Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created May 11, 2011 21:56
Show Gist options
  • Save duncanbeevers/967467 to your computer and use it in GitHub Desktop.
Save duncanbeevers/967467 to your computer and use it in GitHub Desktop.
throttle a given function
function throttle(millis, fn) {
var sched;
return function() {
if (!sched)
sched = setTimeout(function executeAndClear() { fn(); sched = false; }, millis);
};
}
module.exports = throttle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment