Created
December 27, 2013 21:19
-
-
Save venil7/8152745 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
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