Computed Property Name Shorthand Proposal
Jeremy Martin
jmar777 at gmail.com
Thu Aug 27 16:50:05 UTC 2015
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`.
[1]
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object-initializer
On Thu, Aug 27, 2015 at 12:25 PM, Kevin Smith <zenparsing at gmail.com> wrote:
> 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.
>
> Kevin
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
--
Jeremy Martin
661.312.3853
http://devsmash.com
@jmar777
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150827/25f42773/attachment-0001.html>
More information about the es-discuss
mailing list