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 bine shorthand notation with regular notation?
In other words, is the following legit?
var obj = {a, b, c, d: 'foo'};
And if so, are there any gotchas I should be aware of?
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 bine shorthand notation with regular notation?
In other words, is the following legit?
var obj = {a, b, c, d: 'foo'};
And if so, are there any gotchas I should be aware of?
Share Improve this question asked Mar 25, 2016 at 0:17 sfletchesfletche 49.9k31 gold badges109 silver badges120 bronze badges 1- 2 What was result when you tried ? – guest271314 Commented Mar 25, 2016 at 0:21
2 Answers
Reset to default 11Is it possible to bine shorthand notation with regular notation?
Yes. A property definition can be any of the following:
PropertyDefinition :
IdentifierReference
CoverInitializedName
PropertyName : AssignmentExpression
MethodDefinition
Source: ECMAScript 2015 Language Specification
And if so, are there any gotchas I should be aware of?
Nope.
According to Babel yes
See transpiled code results
Babel translates this
var a = 1, b = 2, c = 3;
var obj = {a, b, c, d: 'foo'};
into this in es5
var a = 1,
b = 2,
c = 3;
var obj = { a: a, b: b, c: c, d: 'foo' };
Also found a github repo by Luke Hoban that shows mixed objects being created