Created
June 26, 2012 17:46
-
-
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
This file contains hidden or 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
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