Skip to content

Instantly share code, notes, and snippets.

@Acconut
Created February 28, 2017 19: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 Acconut/3edd7fde6b5fa5231fd2eb8e08fb167c to your computer and use it in GitHub Desktop.
Save Acconut/3edd7fde6b5fa5231fd2eb8e08fb167c to your computer and use it in GitHub Desktop.
// with leading = true and trailing = false
function throttle(func, wait) {
func();
setTimeout(function() {
throttle(func, wait);
}, wait);
}
// with leading = false and trailing = true
function throttle(func, wait) {
setTimeout(function() {
func();
throttle(func, wait);
}, wait);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment