Skip to content

Instantly share code, notes, and snippets.

@iamwilhelm
Created September 1, 2012 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamwilhelm/3563975 to your computer and use it in GitHub Desktop.
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