Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active April 26, 2017 12:27
Show Gist options
  • Save andreasvirkus/4a09d4711d788d01d67c to your computer and use it in GitHub Desktop.
Save andreasvirkus/4a09d4711d788d01d67c to your computer and use it in GitHub Desktop.
export default function debounce(fn, wait = 0) {
let called = false;
return function debounceReturn(...args) {
if (!called) {
const context = this;
called = true;
setTimeout(() => {
called = false;
fn.apply(context, args);
}, wait);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment