Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Created January 14, 2013 03:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansumbrella/4527653 to your computer and use it in GitHub Desktop.
Save sansumbrella/4527653 to your computer and use it in GitHub Desktop.
// debounce a callback function with delay being the longest acceptable time before seeing an effect
function debounce (fn, delay) {
var timeout = null;
return function () {
if( timeout !== null ){ clearTimeout( timeout ); }
timeout = setTimeout( fn, delay );
}
}
// example use:
function callback () { console.log("Called back"); }
window.onresize = debounce( callback, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment