es6-features
es6-features copied to clipboard
Object initializer shorthand for sub-properties?
[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).