Created
August 24, 2020 10:31
-
-
Save ishwarrimal/d10a196c5ceafc52742e55c436f3423c to your computer and use it in GitHub Desktop.
Simple implementation of throttle in JS
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
export function throttle(callback, delay, options = {}) { | |
let flag = true | |
return () => { | |
if (flag) { | |
flag = false | |
setTimeout(() => { | |
callback(options) | |
flag = true | |
}, delay) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment