Skip to content

Instantly share code, notes, and snippets.

@malithmcr
Last active October 25, 2018 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malithmcr/055bcc354f8cca799d65d6e042a87249 to your computer and use it in GitHub Desktop.
Save malithmcr/055bcc354f8cca799d65d6e042a87249 to your computer and use it in GitHub Desktop.
javascript throttle
/**
* throttle
* @param {fn} callback func
* @param {wait} number - wait time
* @public
*/
function throttle(fn, wait) {
var time = Date.now();
return function() {
if ((time + wait - Date.now()) < 0) {
fn();
time = Date.now();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment