Last active
December 18, 2015 12:28
-
-
Save mitchlloyd/5782662 to your computer and use it in GitHub Desktop.
Simple debounce function bases on underscore's.
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
App.debounce = (func, wait) -> | |
timeout = null | |
-> | |
context = this | |
args = arguments | |
immediate = true if args[0] and args[0].now | |
later = -> | |
timeout = null | |
func.apply(context, args) | |
clearTimeout(timeout) | |
if immediate | |
func.apply(context, args) | |
else | |
timeout = setTimeout(later, wait) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment