Created
September 21, 2021 18:22
-
-
Save juliozuppa/4fec18f98d282cee97065470476ac8c0 to your computer and use it in GitHub Desktop.
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
/** | |
* | |
* @param func | |
* @param duration | |
* @returns {function(...[*]=): void} | |
*/ | |
const throttle = function (func, duration) { | |
let shouldWait = false | |
return function (...args) { | |
if (!shouldWait) { | |
func.apply(this, args) | |
shouldWait = true | |
setTimeout(() => { | |
shouldWait = false | |
}, duration) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment