Created
March 1, 2013 02:03
-
-
Save DrSammyD/5061933 to your computer and use it in GitHub Desktop.
underscore debounce wich gives all the arguments called against the function to the function
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
_.debounceAll = (func, wait, immediate) -> | |
timeout = undefined | |
result = undefined | |
results = [] | |
-> | |
results.push | |
context: this | |
args: for val in arguments | |
val | |
later = -> | |
timeout = null | |
result = func.call(this,results) unless immediate | |
callNow = immediate and not timeout | |
clearTimeout timeout | |
timeout = setTimeout(later, wait) | |
result = func.call(this, results) if callNow | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment