Skip to content

Instantly share code, notes, and snippets.

@yocontra
Created April 24, 2012 07:58
Show Gist options
  • Save yocontra/2477684 to your computer and use it in GitHub Desktop.
Save yocontra/2477684 to your computer and use it in GitHub Desktop.
Real function throttle javascript/coffee-script
# Most throttles are actually just delays
# This will only call the function if it hasn't been triggered in (delay)ms
throttle = (fn, delay) ->
return fn if delay is 0
timer = false
return ->
return if timer
timer = true
setTimeout (-> timer = false), delay unless delay is -1
fn arguments...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment