Can Es6 Object Shorthand Notation Be Combined With Regular Object Notation?
With ES6 we can now utilize object shorthand notation for creating objects... var a = 1, b = 2, c = 3; var obj = { a, b, c }; Is it possible to combine shorthand notation with reg
Solution 1:
Is it possible to combine shorthand notation with regular notation?
Yes. A property definition can be any of the following:
PropertyDefinition :IdentifierReferenceCoverInitializedNamePropertyName :AssignmentExpressionMethodDefinition
Source: ECMAScript 2015 Language Specification
And if so, are there any gotchas I should be aware of?
Nope.
Solution 2:
According to Babel yes
Babel translates this
var a = 1, b = 2, c = 3;
var obj = {a, b, c, d: 'foo'};
into this in es5
vara=1,b=2,c=3;varobj= { a:a, b:b, c:c, d:'foo' };
Also found a github repo by Luke Hoban that shows mixed objects being created
Post a Comment for "Can Es6 Object Shorthand Notation Be Combined With Regular Object Notation?"