super return
Michael J. Ryan
tracker1 at gmail.com
Mon Aug 28 20:29:12 UTC 2017
if (arr.find(e => typeof e != 'number')) throw new Error('...');
return arr.map(e => {
if (!...) throw new Error(...);
return e * 2;
});
Odds are you need a conditional block, might as well be try catch.
--
Michael J. Ryan - tracker1 at gmail.com - http://tracker1.info
Please excuse grammar errors and typos, as this message was sent from my
phone.
On Aug 28, 2017 1:17 PM, "Tab Atkins Jr." <jackalmage at gmail.com> wrote:
> On Mon, Aug 28, 2017 at 12:29 PM, Sebastian Malton
> <sebastian at malton.name> wrote:
> > I have seen some people want to modify some of the array prototype
> > functions, especially forEach, so that returning from them returns a
> value.
> > However, I have also seems that this could break things since in some
> cases,
> > again forEach, the return value in explicitly defined.
> >
> > Thus I propose the new syntax `super return` and any other positive
> number
> > of supers. This syntax is currently not valid in any scenario and with
> the
> > current meaning of super seems, to me at least, relativity easy to
> > understand.
> >
> > The outcome of this basically means "return from current context up one
> > level and then return from there".
> >
> > A current method of doing this is by using try / catch but it is not
> ideal.
> > Using the above method I believe that it would be able to be better
> > optimized.
>
> This has been suggested in the past, by adding a fourth argument to
> the callback signature passing an opaque "halt" value. Returning the
> halt value would end execution of the looping function prematurely.
> No reason to add new syntax for this, plus hooks for userland to take
> advantage of it, when we can just use something that userland could
> adopt *today*.
>
> (As an added bonus, it would make the callback arguments be Element,
> Index, Collection, Halt, finally spelling out Brendan's full last
> name. ^_^)
>
> ~TJ
> _______________________________________________
> 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/20170828/a8390398/attachment.html>
More information about the es-discuss
mailing list