Skip to content

Instantly share code, notes, and snippets.

@mitchlloyd
Last active December 18, 2015 12:28
Show Gist options
  • Save mitchlloyd/5782662 to your computer and use it in GitHub Desktop.
Save mitchlloyd/5782662 to your computer and use it in GitHub Desktop.
Simple debounce function bases on underscore's.
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