Created
June 11, 2022 20:56
-
-
Save balsanka/dd8592be032c58b388e8769f63046c48 to your computer and use it in GitHub Desktop.
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 throttling(callBack, timer) { | |
let isBusy = false; | |
let timeoutId; | |
return function () { | |
let context = this; | |
if (!isBusy) { | |
isBusy = true; | |
callBack.call(context, ...arguments); | |
timeoutId = setTimeout(() => { | |
isBusy = false; | |
clearTimeout(timeoutId); | |
}, timer); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment