Template literal propery names in object literals

Jordan Harband ljharb at gmail.com
Thu Nov 7 19:45:56 UTC 2019


Anything dynamic - computed - should be in brackets, since that's what that
indicates.

Thus, template literals with substitutions must require brackets.

Based on sentiments like
https://github.com/tc39/ecma262/issues/1399#issuecomment-452910799, either
all template literals or none should be permitted in a given position.

Thus, no change is possible.

On Thu, Nov 7, 2019 at 10:00 AM Alex Kodat <akodat at rocketsoftware.com>
wrote:

> Thanks Gus,
>
> Good stuff. Though I think I’d take a different tack on the discussion at
> that link, especially as I think the template literals should allow
> substitutions (why not?):
>
> let obj = { `${Date()}`: 1};
>
> I guess the tack I would take in the spec would be to add TemplateLiteral
> to ComputedPropertyName and not worry about whether or not it's a
> NoSubstitutionTemplate.
>
> Thanks
>
> ------
> Alex Kodat
> Senior Product Architect
> Rocket Software
> t: +1 781 684 2294 • m: +1 315 527 4764 • w:
> http://www.rocketsoftware.com/
>
> From: Gus Caplan <me at gus.host>
> Sent: Thursday, November 7, 2019 11:13 AM
> To: Alex Kodat <akodat at rocketsoftware.com>
> Cc: es-discuss at mozilla.org
> Subject: Re: Template literal propery names in object literals
>
> Related discussion
> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftc39%2Fecma262%2Fissues%2F1399&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736614052&sdata=xDiwNTWHvdfIakrVFe6RmiP5pLHzC0i%2BoRNwKgvTMvc%3D&reserved=0
>
> On Thu, Nov 7, 2019 at 8:46 AM Alex Kodat <mailto:
> akodat at rocketsoftware.com> wrote:
> Just curious. Is there a reason template literals are not allowed as
> property names in object literals? I can do:
>
>    let obj = {'foo bar': 1};
>
> and
>
>    let obj = {"foo bar": 1};
>
> but not
>
>    let obj = {`foo bar`: 1};
>
> It doesn't seem that allowing the latter would present any syntactic
> problems and seems like almost an oversight that it's not allowed.
>
> The main reason I ask is that we've gone completely over to using template
> literals for all our literals (why not?) and was surprised that we can't
> use a template literal as an object literal property name. Obviously, we
> can do:
>
>    let obj = {[`foo bar`]: 1};
>
> And given that square brackets allow arbitrary expressions for propery
> names, it wouldn't seem that supporting template literals for object
> literal property names would not present any daunting implementation issues.
>
> I guess I'd argue that the Principle of Least Astonishment and/or
> completeness suggests that JS should support this.
>
> Sorry if this has been asked before but couldn't find anything in the
> archive.
>
> Thanks
>
> ------
> Alex Kodat
> Senior Product Architect
> Rocket Software
> t: +1 781 684 2294 • m: +1 315 527 4764 • w:
> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736623994&sdata=hTNIou6kPg5Ms%2FnIK%2BFVjrWa7mcGDtAbSJrVLVufxQU%3D&reserved=0
>
> ================================
> Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA
> 02451 ■ Main Office Toll Free Number: +1 855.577.4323
> Contact Customer Support:
> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmy.rocketsoftware.com%2FRocketCommunity%2FRCEmailSupport&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736623994&sdata=FnuZYm9iu1AHZS4TNuA1TF95h0DzCh1HyF%2FN3CLoQ9M%3D&reserved=0
> Unsubscribe from Marketing Messages/Manage Your Subscription Preferences -
> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fmanage-your-email-preferences&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736623994&sdata=xWVTW4Dr2qH1Hfc9woMu1ah6M9AzNcSkVot1y8A9Dmc%3D&reserved=0
> Privacy Policy -
> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fcompany%2Flegal%2Fprivacy-policy&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736633951&sdata=X3vLto4DdTHU4roy6wY0Ep%2BXVucGx3v9Dw28KsPzfsg%3D&reserved=0
> ================================
>
> This communication and any attachments may contain confidential
> information of Rocket Software, Inc. All unauthorized use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> notify Rocket Software immediately and destroy all copies of this
> communication. Thank you.
> _______________________________________________
> es-discuss mailing list
> mailto:es-discuss at mozilla.org
>
> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&data=02%7C01%7C%7C9e20b9f578574ad67b1308d763a5b814%7C79544c1eed224879a082b67a9a672aae%7C0%7C1%7C637087435736633951&sdata=f28Os3jqAQ5VHGcxQ5auW5vcOuoC7s2QupBH5AR52yQ%3D&reserved=0
> ================================
> Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA
> 02451 ■ Main Office Toll Free Number: +1 855.577.4323
> Contact Customer Support:
> https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
> Unsubscribe from Marketing Messages/Manage Your Subscription Preferences -
> http://www.rocketsoftware.com/manage-your-email-preferences
> Privacy Policy -
> http://www.rocketsoftware.com/company/legal/privacy-policy
> ================================
>
> This communication and any attachments may contain confidential
> information of Rocket Software, Inc. All unauthorized use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> notify Rocket Software immediately and destroy all copies of this
> communication. Thank you.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20191107/96243ee8/attachment.html>


More information about the es-discuss mailing list