Skip to content

Instantly share code, notes, and snippets.

@DrSammyD
Created March 1, 2013 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrSammyD/5061933 to your computer and use it in GitHub Desktop.
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
_.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