Skip to content

Instantly share code, notes, and snippets.

@venil7
Created December 27, 2013 21:19
Show Gist options
  • Save venil7/8152745 to your computer and use it in GitHub Desktop.
Save venil7/8152745 to your computer and use it in GitHub Desktop.
var throttle2 = function(fn, threshhold, scope) {
var time, last = 0, handle,
args = arguments;
threshhold = threshhold || 250;
return function() {
var that = this;
time = +new Date();
if ((time - last) > threshhold) {
last = time;
// console.timed_log('ran');
clearTimeout(handle);
fn.apply(scope || that, args);
} else {
clearTimeout(handle);
handle = setTimeout(function(){
last = time;
// console.timed_log('ran witheld');
fn.apply(scope || that, args);
}, threshhold);
// console.timed_log('witheld');
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment