Created
January 22, 2014 14:13
-
-
Save desandro/8559356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original by John Hann | |
// http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ | |
function debounce( fn, threshold ) { | |
var timeout; | |
return function debounced() { | |
var _this = this; | |
var args = arguments; | |
if ( timeout ) { | |
clearTimeout( timeout ); | |
} | |
timeout = setTimeout( function delayed() { | |
fn.apply( _this, args ); | |
timeout = null; | |
}, threshold || 100 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment