Proposal: result-forwarding ternary operator

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Sep 20 12:36:52 UTC 2017


combining all the things (arrow with implicit return + arguments default +
ternary)

```js
const newFoo = ((x = getSomething()) => x ?
  (doSomethingFirst(), x.doSomething()) :
  doSomethingElse()
)();
```

So yeah, we probably don't need yet another pattern/new syntax to do that.

Regards



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

> 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
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170920/6fb7ba04/attachment.html>


More information about the es-discuss mailing list