On Fri, Mar 16, 2018 at 1:30 PM, Sebastian Malton <[email protected]> wrote:
> Hello currently the following is a possible way to define an object.
>
> ```
> var d = { a, b, c };
> ```
>
> But this only works if the fields are already variables.
>
> So if you wanted to select some fields from an object within you have to use
> temp variables, reference the field by name but without the temporary
> variables, or use some immediately called functions which is messy.

You can just use ordinary object-creation syntax.  The syntax you're
referencing is a shorthand, specifically for the limited, but common,
case where you want to add a field with the same name as a variable.
Like:

> So I propose the following syntax:
>
> ```
> var d = {
>     a,
>     b,
>     { c }: e
> };
> ```
>
> Here d will have the fields [a, b, c] and the values are the variable a,
> variable b, and value e.c.

You can just write:

```
var d = {
  a,
  b,
  c: e.c
};
```

(Assuming that's what you meant, and not `c.e` for the last field's value.)

~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to