Proposal: result-forwarding ternary operator

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Sep 20 12:04:07 UTC 2017


On Wed, Sep 20, 2017 at 12:52 PM, Bob Myers <rtm at gol.com> wrote:
>
> 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"?

Sorry, my example was missing a `break`. And it may have been off, since
the `break` (rather than `x.foo`) would be the last executed statement. The
main point was: You can use statements in `do` expressions, not with the
comma operator.

> By the way, in current iterations of the `do` concept is there
> a `return`?

As far as I could tell reviewing the discussion hat the TC39 proposals list
refers to, it hasn't been decided. As someone points out in the comments,
with `return` it's effectively an IIFE. Folks seem quite interested in `do`
expressions but I'm having trouble seeing much need for them in a world
with IIFEs and arrow functions:

```js
const x = (() => {
    for (const x of getTheThings()) {
        if (x.id == something) {
            return x.foo;
        }
    }
})();
```

I mean, yes, even with `return` the `do` expression version of that would
be *slightly* more concise, but...

We're off-topic, though. This is about `do` expressions. The thread is
about "result-forwarding ternary operators".

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170920/d5894265/attachment.html>


More information about the es-discuss mailing list