Template literal propery names in object literals

Gus Caplan me at gus.host
Thu Nov 7 17:12:31 UTC 2019


Related discussion https://github.com/tc39/ecma262/issues/1399

On Thu, Nov 7, 2019 at 8:46 AM Alex Kodat <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: www.rocketsoftware.com
>
> ================================
> 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/52109bef/attachment.html>


More information about the es-discuss mailing list