-
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
Braceless object return
#1263
Comments
How about separating the object to be returned by one line? I think it's readable.
|
The way it is now is inconsistent with the rest of the language—function calls, assignment, nested objects—so yeah, this should probably be fixed. The implicit return separated by an empty line is readable, but not as clear as it could be. Additionally, while it is a passable workaround for the usual case, it can't help you when you need to put an explicit return somewhere. |
Also, given CoffeeScript's lack of surrounding braces or keywords for On Mon, Apr 4, 2011 at 11:28 PM, erisdiscord
|
I'm sorry @satyr, I must have been unclear in my original post—I I'm asking for comments on potentially amending CoffeeScript's Given that you can already pass an object literal to a function call like this:
It feels natural to be able to do the same thing with returning an On Tue, Apr 5, 2011 at 4:25 PM, satyr
|
Note that this syntax is an inconsitency in the language (there are lingering issues with it). Adding another similar specialcase may worsen the situation. (What about |
Yep -- agreed -- I don't think we really need to be adding an additional special case for this. |
If you really need this style, you can do:
|
@jashkenas: why the re-open? |
Because we're thinking about fixing this in that other ticket. Although we can certainly close one of them as a dupe, if you like. |
Not really.
|
@satyr haha, subtle, wow. |
I've taken to using this for explicit early returns: return {} =
here: 'is'
my: 'object' ...and this for implicit object returns: {} =
here: 'is'
my: 'object' (that second one not being mentioned on the StackOverflow thread). |
I’ve noticed that this bug is the root of several similar issues. I’m trying to trace it down but not having much luck so far. Parsing/lexing experts, can anyone tell me why this: throw
a: 1
b: 2 compiles as you’d expect, but if you replace EDIT: Looks like it’s in |
I'd like to be able to return an object literal from a function without typing any braces:
Right now, you have to do this:
Not terrible, but come on... We don't wanna type no stinking braces! LOL
Actually, this is legal but I think it looks confusing:
The text was updated successfully, but these errors were encountered: