Support () => {}() syntax?

Michał Wadas michalwadas at gmail.com
Thu Sep 29 22:13:49 UTC 2016


Similar proposal is already here, do expressions.

On 30 Sep 2016 12:06 a.m., "Olivier Lalonde" <olalonde at gmail.com> wrote:

> I occasionally write IIFE to avoid introducing `let` variables, e.g.:
>
> ```
> const thumb = ({ width, height }) => {
>   const { w, h } = (() => {
>     // if either width or height is set, don't set any default
>     if (Number.isInteger(width) || Number.isInteger(height)) {
>       return { w: width, h: height }
>     }
>     return { w: 400, h: 400 }
>   })()
>   // ...
> }
> ```
>
> One annoyance is that arrow functions must be wrapped inside parens in
> order to be called. In other words, you can do `(() => {})()` but not `()
> => {}()`. The latter syntax is less verbose but is not supported.
>
> I understand that the short style, e.g. `val => val + 1()` or `val =>
> (fn())()` would be ambiguous but I don't believe the `() => {}` style would
> be. Of course it gets a bit ambiguous when you get `() => () => {}()` but
> that form isn't very common for IIFE.
>
> Just wondering if this has been discussed before.
>
> --
> - Oli
>
> Olivier Lalonde
> http://www.syskall.com <-- connect with me!
>
> _______________________________________________
> 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/20160930/bfc9c5e0/attachment-0001.html>


More information about the es-discuss mailing list