Skip to content

Instantly share code, notes, and snippets.

@cms
Created Jul 24, 2019
Embed
What would you like to do?
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