Computed Property Name Shorthand Proposal
I'd expect the following to work, given that the prop expression evaluates to 'bar', and bar is in context.
var foo = 'bar' var bar = 'ponyfoo' var baz = { [foo] } console.log(baz) // <- { bar: 'ponyfoo' }
Hmmm... I'm not sure I would expect any such thing. It seems like you're proposing some kind of dynamic eval-ish variable binding lookup, which is probably going to be a no-go.
I'm usually lousy at interpreting the spec (yet here I go!), but I think the behavior is explained here [1]:
PropertyDefinition[Yield] : IdentifierReference[?Yield] CoverInitializedName[?Yield] PropertyName[?Yield] : AssignmentExpression[In, ?Yield] MethodDefinition[?Yield]
PropertyName[Yield,GeneratorParameter] : LiteralPropertyName [+GeneratorParameter] ComputedPropertyName [~GeneratorParameter] ComputedPropertyName[?Yield]
LiteralPropertyName : IdentifierName StringLiteral NumericLiteral
ComputedPropertyName[Yield] : [ AssignmentExpression[In, ?Yield] ]
There are aspects to that grammar that I don't fully grok yet, but your { [foo] }
example appears to be trying to combine the IdentifierReference
form (which doesn't support an AssignmentExpression
) and the PropertyName: AssignmentExpression
form (which requires the AssignmentExpression
).
In other words, all paths in that grammar that lead to a ComputedPropertyName
being valid also require the right-hand AssignmentExpression
.
That's exactly what this is. I appreciate the beauty in symmetry, but I think -1.
Alexander Jones wrote:
That's exactly what this is. I appreciate the beauty in symmetry, but I think -1.
I second this.
I'd expect the following to work, given that the prop expression evaluates to 'bar', and bar is in context.
The following works
Sorry for not being quite spec-speak versed, this is my first message here. Nico
github bevacqua · blog ponyfoo.com · twitter twitter.com/nzgb · book bevacqua.io/buildfirst · career careers.stackoverflow.com/bevacqua ·about bevacqua.io