Skip to content

Instantly share code, notes, and snippets.

@RSNara
Last active August 17, 2017 21:50
Show Gist options
  • Save RSNara/7a9766a125e53c41c01b194a836bdfd0 to your computer and use it in GitHub Desktop.
Save RSNara/7a9766a125e53c41c01b194a836bdfd0 to your computer and use it in GitHub Desktop.
An implementation of debounce.
function debounce(fn) {
let token = null;
return function thunk() {
if (token) {
cancelAnimationFrame(token);
}
token = requestAnimationFrame(() => {
token = null;
thunk.apply(this, arguments);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment