Created
April 24, 2012 07:58
-
-
Save yocontra/2477684 to your computer and use it in GitHub Desktop.
Real function throttle javascript/coffee-script
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
# Most throttles are actually just delays | |
# This will only call the function if it hasn't been triggered in (delay)ms | |
throttle = (fn, delay) -> | |
return fn if delay is 0 | |
timer = false | |
return -> | |
return if timer | |
timer = true | |
setTimeout (-> timer = false), delay unless delay is -1 | |
fn arguments... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment