Last active
July 22, 2024 11:49
-
-
Save kettanaito/9ae2fdda8e57b9b8fa314b9705b7aa5a to your computer and use it in GitHub Desktop.
Debounce vs Throttle: Throttle
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, timeout) { | |
let wait = false; | |
return function (...args) { | |
if (!wait) { | |
func(...args) | |
wait = true; | |
setTimeout(function () { | |
wait = false; | |
}, timeout); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment