Skip to content

Instantly share code, notes, and snippets.

@shcyiza
Last active July 28, 2020 09:59
Show Gist options
  • Save shcyiza/e64eb3bbf3d1d8318340f8e1b5d320a4 to your computer and use it in GitHub Desktop.
Save shcyiza/e64eb3bbf3d1d8318340f8e1b5d320a4 to your computer and use it in GitHub Desktop.
function Debounce(fn, wait = 300) {
this.timeout = null;
return (...args) => {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => fn(...args), wait);
}
}
// Usage
const debounce = new Debounce(message => {console.log(message)}, 100);
debouncer("first");
debouncer("2de");
// expect: "2de"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment