Created
July 24, 2019 19:14
-
-
Save cms/81f39e2d0e5ecba3b1cdbf4bb67205b4 to your computer and use it in GitHub Desktop.
Small debounce function
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
/** | |
* Small debounce function. | |
* | |
* by Christian C. Salvadó <c@cms.gt> | |
* MIT Style license, 2019 | |
*/ | |
function debounce(fn, ms = 0) { | |
let timer = 0 | |
return function(...args) { | |
clearTimeout(timer) | |
timer = setTimeout(fn.bind(this, ...args), ms) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment