Created
August 25, 2015 09:24
-
-
Save edgarberm/5741fe35c664cf9618c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function throttle ( fn, threshhold, scope ) { | |
threshhold || (threshhold = 250); | |
var last, | |
deferTimer; | |
return function () { | |
var context = scope || this; | |
var now = +new Date, | |
args = arguments; | |
if ( last && now < last + threshhold ) { | |
// hold on to it | |
clearTimeout(deferTimer); | |
deferTimer = setTimeout( function () { | |
last = now; | |
fn.apply( context, args ); | |
}, threshhold ); | |
} else { | |
last = now; | |
fn.apply(context, args); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment