Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created April 27, 2018 05:43
Show Gist options
  • Save cyan33/c7b8587152ff69e3a1f3dd683047336a to your computer and use it in GitHub Desktop.
Save cyan33/c7b8587152ff69e3a1f3dd683047336a to your computer and use it in GitHub Desktop.
A debounce that makes more sense to me (written by myself)
function debouce(fn, wait = 99) {
let timeout = null;
function process(args) {
fn(args);
timeout = null;
}
return function() {
if (!timeout) {
timeout = setTimeout(process.bind(null, arguments), wait);
} else {
clearTimeout(timeout)
timeout = setTimeout(process.bind(null, arguments), wait)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment