Support () => {}() syntax?

Rick Waldron waldron.rick at gmail.com
Thu Sep 29 22:59:05 UTC 2016


On Thu, Sep 29, 2016 at 3:14 PM Michał Wadas <michalwadas at gmail.com> wrote:

> Similar proposal is already here, do expressions.
>

Additionally...

>
> 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 }
>>   })()
>>   // ...
>> }
>> ```
>>
>
Why introduce the function and cognitive overhead?

const thumb = ({ width, height }) => {
  const w = Number.isInteger(width) ? width : 400;
  const h = Number.isInteger(height) ? height : 400;
  // ...
}


Either way, `do` expressions are what you're looking for.


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160929/a49d3739/attachment.html>


More information about the es-discuss mailing list