Last active
November 17, 2019 08:15
-
-
Save intrnl/30e0e04ef46a441a6d7110b2c24b9cfa to your computer and use it in GitHub Desktop.
Function throttling
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, ms) { | |
let throttled = false; | |
return function () { | |
const call = () => fn.apply(this, arguments); | |
if (throttled) return; | |
throttled = true; | |
setTimeout(() => throttled = false); | |
call(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment