1

Using the new shorthand feature in ES6 for object literals, is it possible to use obj.id and have it parse as id: obj.id? Wondering if I've missed something in the new spec...

create(obj) {
    this.connection.send({
        obj.id
    });
    this.add(obj);
},
benhowdle89
  • 36,900
  • 69
  • 202
  • 331

2 Answers2

2

No, there is not. Shorthands do only work for variables, so you should use {id: obj.id}.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

Although Bergi response is correct, you could create a variable for id:

create(obj) {
    const { id } = obj;
    this.connection.send({ id });
    this.add(obj);
},

For the specific case you mention it's a overload, but on other cases it might be useful.

a--m
  • 4,716
  • 1
  • 39
  • 59