Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Created May 16, 2017 18:38
Show Gist options
  • Save TravisMullen/74dd1b0fb5ca3244defe46c04fd3e928 to your computer and use it in GitHub Desktop.
Save TravisMullen/74dd1b0fb5ca3244defe46c04fd3e928 to your computer and use it in GitHub Desktop.
limit events per second
// limit the number of events per second
function throttle(callback, delay) {
var previousCall = new Date().getTime();
return function() {
var time = new Date().getTime();
if ((time - previousCall) >= delay) {
previousCall = time;
callback.apply(null, arguments);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment