Created
May 16, 2017 18:38
-
-
Save TravisMullen/74dd1b0fb5ca3244defe46c04fd3e928 to your computer and use it in GitHub Desktop.
limit events per second
This file contains hidden or 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
// 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