Skip to content

Instantly share code, notes, and snippets.

@oliv37
Last active July 19, 2019 18:07
Show Gist options
  • Save oliv37/9ef4e01f9f3c9b4caad893cfd147c27f to your computer and use it in GitHub Desktop.
Save oliv37/9ef4e01f9f3c9b4caad893cfd147c27f to your computer and use it in GitHub Desktop.
throttle es6 implementation with immediate call
function throttle(func, wait = 100) {
let timer = null;
return function(...args) {
if (timer === null) {
func.apply(this, args);
timer = setTimeout(() => timer = null, wait);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment