Skip to content

Instantly share code, notes, and snippets.

@iamklim
Created June 5, 2022 20:16
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 iamklim/2ae068b435eec5d668b57f46bea7910a to your computer and use it in GitHub Desktop.
Save iamklim/2ae068b435eec5d668b57f46bea7910a to your computer and use it in GitHub Desktop.
Simple ES6 throttle
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