es6-features icon indicating copy to clipboard operation
es6-features copied to clipboard

Object initializer shorthand for sub-properties?

Open devuxer opened this issue 6 years ago • 0 comments

[QUESTION]

Is there any way to shorten the following with ES6 features?

return { op: this.op, lhs: this.lhs, rhs: this.rhs };

I was hoping I could do something like this...

return { this.op, this.lhs, this.rhs };

...but that results in a syntax error.

It is possible to do this...

const { op, lhs, rhs } = this;
return { op, lhs, rhs };

...but that's still a bit verbose (you have to repeat {op, lhs, rhs} twice, which becomes inefficient with longer or more properties).

devuxer avatar Mar 01 '18 00:03 devuxer