-
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
More clarification about implicit object literals #575
Comments
Big big +1 on this. Given how often large parameter sets are used in JS API design, I'd really like to see some kind of easy multiline method call with implicit object literal. Here's a concrete example I pulled out of my project that I think will occur many times for anyone using CoffeeScript
|
+1, but let's generalize this a bit. The example you give is a special case of the following:
This is currently a syntax error, but it should be interpreted as
You can get around this using a backslash escape after each line (except the last), but since the syntax is unambiguous, backslash escapes shouldn't be necessary. Here's a more complete test case (though without any object literals):
should be interpreted as |
I reckon this is going to be quite the challenge to allow mainly because this is valid:
and it produces quite the different output to what is expected. |
@StanAngeloff: So, the one difference between the output from the snippet you gave and the output I expect is that
but what is this, Lisp? :) Particularly now that we allow significant indentation for YAML-style object literals, I think it's very important for CoffeeScript to allow significant indentation for function arguments. Do you agree? |
I have tried the above myself on a few occasions (as well with impl object literals) so I kind of expected it to work as per this ticket so I am in no disagreement. However I recall Jeremy allowing more flexible indentation inside functions as a result of several issues posted on the tracker so I am unsure how easy it is going to be to allow what we are all expecting. |
Here's the minimal test case that demonstrates what's problematic about this idea:
Right now, that parses into:
With this ticket, it would also parse to:
If you want to call against an implicit object, you need to mark that object as callable, either by using parentheses for the call, or braces for the object ... Or does anyone have a way to fix this ambiguous parse? Remember that there can be an arbitrarily complex expression as the condition to the "if". |
I guess this would be backwards incompatible in a pretty painful way (at least as bad as symbology) but what if you could add a I don't think that's a good solution, but honestly I don't know if there is one...I think the combination of semantic whitespace, paren-free function calls, and brace-free object literals is a recipe for confusing behavior. |
@jashkenas: Your example certainly gave me pause. But on reflection, I think it's acceptable—even ideal—for
to retain its current meaning of
mean Will it flummox newbies? Yes, but not as much as the current behavior when passing function arguments that span multiple lines, which I can attest has tripped me up repeatedly. |
Alright folks, here's the commit for this: http://github.com/jashkenas/coffee-script/commit/7a0d95c61243f8bd90750e2f411edf814666d5df It doesn't go into the weeds and allow syntax like this:
... which I think would set a poor precedent, but does allow implicit objects within a block to be treated as arguments, as if you had added the
Compiles into this JavaScript:
I'm digging it. Thanks for opening the ticket. |
This still leaves Having to write |
When moving code over to .9, I was surprised that you couldn't use implicit object literals for function arguments:
Sweet, that means I can create classes with objects this way, right?
Guess not. How about function calls instead of constructors?
Bummer. Is this a bug? Or difficult to pull off in the grammer?
If it is difficult to implement, then I think this should be mentioned in the doc because it seems natural to take the kids example and add a function call to it.
The text was updated successfully, but these errors were encountered: