Skip to content

Instantly share code, notes, and snippets.

@michaelmano
Last active June 11, 2018 07:16
Show Gist options
  • Save michaelmano/832dce5f0a026678387c1f4048b9fa25 to your computer and use it in GitHub Desktop.
Save michaelmano/832dce5f0a026678387c1f4048b9fa25 to your computer and use it in GitHub Desktop.
ES6 Callback debounce
"use strict"
/**
* window.addEventListener('scroll', debounce(() => console.log('Window scrolled.')));
*/
const debounce = function debounce(callback, delay = 250) {
let timeout = null;
return () => {
clearTimeout(timeout);
timeout = setTimeout(() => callback.apply(this, arguments), delay);
};
};
export default debounce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment