Created
November 13, 2020 09:14
-
-
Save the-fejw/2b7ec4aa2acda6420cbf7d7a73801226 to your computer and use it in GitHub Desktop.
js throttle source example
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
function throttle(fn, wait) { | |
let timer = false; | |
return function() { | |
if (!timer) { | |
fn.apply(this, arguments); | |
timer = setTimeout(() => { | |
clearTimeout(timer); | |
timer = false; | |
}, wait); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment