-
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
{foo.bar} as shorthand for {bar: foo.bar} #1089
Comments
Frankly, imho anything standing at hash key position should be treated as stringified hash key. |
ref #482 There wasn't much discussion happening in there. I agree with Jeremy in the sense that calls shouldn't be treated as DRY shorthands, but property accessors are different and they are quite useful. |
I certainly agree that calls should not be allowed. This is already the case with the
To take the other part of Jeremy's example, I see no problem with
being shorthand for
Neither is pretty, but the former is a definite improvement. I also feel like it's an unfortunate inconsistency that |
I agree, I have often wanted to do: Since it works for |
Yep, this is a duplicate of #482, and is untenable for the same reason. If we allow:
We also must allow:
... which isn't going to work well. |
Coco made this possible. |
I am also planning to make this possible with my coffee rewrite. |
Woot. Planning a fork, or directly into master? |
Jeremy, could you explain what you mean by "untenable"? Is
really worse than
? Obviously neither is great style, but disallowing the former also means disallowing the pleasantly readable
|
Yes ... I mean that it's massively inconsistent. You're treating the value as both the key and value of the object literal, and you're restricting the case so that you can use any value ... as long as the final bit of it happens to be a plain property ... and that property happens to be a valid identifier string. |
@michaelficarra: sounds awesome. If you feel like working on a branch in the main repo, go right ahead. |
Jeremy, I'm not seeing the inconsistency. Surely it's inconsistent that |
Yes, and if anything, we should remove |
That doesn't seem like too much to ask. I think that's intuitive. If you try anything else, you should only expect a syntax error.
Glad you're supportive. Some people wouldn't see this as a step forward, but I do, and I'm glad you do too.
Yes. This. |
Currently, you can write
as shorthand for
and, in destructuring assignment / pattern matching (trying to make this issue search-friendly...),
as shorthand for
However,
{foo.bar}
is a parse error in either context. There's a common use case for this: grabbing a subset of multiple objects simultaneously. For instance, in some code I was just writing, a function takesoptions
, adds some other things, and passes some of those options on to another function in an unfortunately repetitious manner:This could be shortened nicely to
The
{@bar}
syntax was introduced by issue 721, where StanAngeloff mentions an old ticket on this, but I couldn't find it [Edit: It was 482; see Stan's comment below.]. Probably best to start a fresh discussion anyway. Have at it.The text was updated successfully, but these errors were encountered: