Last active
July 19, 2019 18:07
-
-
Save oliv37/9ef4e01f9f3c9b4caad893cfd147c27f to your computer and use it in GitHub Desktop.
throttle es6 implementation with immediate call
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
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