Skip to content

Instantly share code, notes, and snippets.

@vinicius5581
Last active May 28, 2019 15:24
Show Gist options
  • Save vinicius5581/85e28d74259f4dce3649f7acc32da610 to your computer and use it in GitHub Desktop.
Save vinicius5581/85e28d74259f4dce3649f7acc32da610 to your computer and use it in GitHub Desktop.
const debounce = (fn, time) => {
let timerId = null
return (...args) => {
if (timerId) {
clearTimeout(timeId)
}
timeId = setTimeout(() => {
fn(...args)
}, time)
}
}
input.addEventListener('keyup', debounce(e => console.log(e), 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment