Skip to content

Instantly share code, notes, and snippets.

@iamwilhelm
Created September 1, 2012 04:42
Show Gist options
  • Select an option

  • Save iamwilhelm/3563975 to your computer and use it in GitHub Desktop.

Select an option

Save iamwilhelm/3563975 to your computer and use it in GitHub Desktop.
Default arguments in javascript/coffeescript
# Here's a way to do default arguments in coffeescript with combinators
defaultArgs = (defaults...) ->
(callback) ->
(args...) ->
callback.apply @, ((arguments[i] || def) for i, def of defaults)
# However, coffeescript already supports default arguments, so if you translate it to javascript,
# it's a way to do default arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment