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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss