Skip to content

Instantly share code, notes, and snippets.

Last active Jun 28, 2016
What would you like to do?
Stand-alone, straightforward debounce function. Executes the callback at the end (no option for executing at start).
function debounce( callback, delay, context ) {
var timer;
return function () {
var _this = context || this,
args = arguments;
// Clear a timer which has been created earlier in the sequence of calls.
timer && clearTimeout( timer );
// (Re-)start the timer, ie create a new one.
timer = setTimeout( function () {
callback.apply( _this, args );
}, delay );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment