Skip to content

Instantly share code, notes, and snippets.

@cms
Created July 24, 2019 19:14
Show Gist options
  • Save cms/81f39e2d0e5ecba3b1cdbf4bb67205b4 to your computer and use it in GitHub Desktop.
Save cms/81f39e2d0e5ecba3b1cdbf4bb67205b4 to your computer and use it in GitHub Desktop.
Small debounce function
/**
* 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