Proposal: result-forwarding ternary operator

Bob Myers rtm at gol.com
Wed Sep 20 11:52:33 UTC 2017


Could you please clarify how the system would know that some random
expression in the middle of something like this for/if construct should be
treated as a sort of "return"? I can understand that the **last**
expression in a block would be the return value, but how would it know that
`x.foo` was an implicit return? By the way, in current iterations of the
`do` concept is there a `return`?
```js
const x = do {
    for (const x of getTheThings()) {
        if (x.id == something) {
            x.foo;
        }
    }
};
```

On Wed, Sep 20, 2017 at 4:11 PM, T.J. Crowder <
tj.crowder at farsightsoftware.com> wrote:

> On Wed, Sep 20, 2017 at 11:28 AM, Naveen Chawla <naveen.chwl at gmail.com>
> wrote:
> >
> > The comma operator seems to make the `do` concept redundant, at
> > least for me.
>
> No, not at all. Again: With the comma operator, you can't use
> *statements*, only expressions. With the `do` expression, you can use
> actual statements:
>
> ```js
> const x = do {
>     for (const x of getTheThings()) {
>         if (x.id == something) {
>             x.foo;
>         }
>     }
> };
> ```
>
> ...which is basically:
>
> ```js
> const x = getTheThings().find(x => x.id == something).foo;
> ```
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170920/a3724fc6/attachment.html>


More information about the es-discuss mailing list