-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument Enhancements (Defaults and Splats) #16
Comments
Like it alot. Could also have ruby 2.0 style named arguments? E.g
Might be more complexity than you're willing to add at this point. |
I like both ideas. Weepy's can be implemented using objects (The "normal" way in plain Javascript). |
I like weepy's idea too, -- it's a nice shorthand in Ruby, and it would be nice to have it here. The only twist is that it's already valid CoffeeScript syntax.
Compiles into:
So we might need to keep the brackets wrapper just to be specific about what you mean. |
how does ruby manage it ? |
Well, in Ruby, assignment uses |
Alright -- splats in function definitions are now on master. Kick the tires if you'd like. This:
Compiles into:
|
And splats are now available as arguments to function calls. Calling the function defined above:
Compiles into:
|
Going to leave default parameters out for the time being, because they would significantly complicate the grammar and have the potential to look really confusing within function assignments. If anyone has a proposal for what default parameters should look like, feel free to open a new ticket. Closing this one. (If you'd like to have default arguments now, you can use the |
New ticket: http://github.com/jashkenas/coffee-script/issues#issue/92 Problem with using ||= is that it is bug-prone.
|
Think about adding argument defaults to CoffeeScript function definitions. Something along the lines of:
Ideally, the arguments with default values could occur anywhere in the list.
Also, splats to siphon up the rest of the arguments:
Neither of these should be too hard to implement -- both can be accomplished by inserting an expression that does the work at the top of the Code body.
The text was updated successfully, but these errors were encountered: