Created
June 5, 2022 20:16
-
-
Save iamklim/2ae068b435eec5d668b57f46bea7910a to your computer and use it in GitHub Desktop.
Simple ES6 throttle
This file contains 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
const throttle = (func, ms) => { | |
let isThrottled = false; | |
return (...args) => { | |
if (!isThrottled) { | |
func(...args); | |
isThrottled = true; | |
setTimeout(() => { | |
isThrottled = false; | |
}, ms); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment