Skip to content

Instantly share code, notes, and snippets.

@kristianpd
Created June 26, 2012 17:46
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 kristianpd/2997396 to your computer and use it in GitHub Desktop.
Save kristianpd/2997396 to your computer and use it in GitHub Desktop.
debounce option on function to only result in one call within time threshold
Function::debounce = (threshold, functionArgs...) ->
@_debounceTimeout = @_debounceTimeout ? null
do =>
delayed = =>
@.apply(@, functionArgs)
@_debounceTimeout = null;
if @_debounceTimeout
clearTimeout(@_debounceTimeout)
@_debounceTimeout = setTimeout(delayed, threshold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment