Support () => {}() syntax?

Olivier Lalonde olalonde at gmail.com
Fri Sep 30 02:57:03 UTC 2016


Thanks, I wasn't aware of `do` expressions.

> Why introduce the function and cognitive overhead?

Not that it really matters (I was just giving an example) but your
alternative isn't achieving the same thing, which is to set a default to
width and height if and only if *neither* height or width is set. (e.g.
thumb({ width: 100 }) should set `w = 100` and `h = undefined` not `w =
100` and `h = 400` but thumb({}) should set `w=400` and `h=400`.

Anyways, I'll try to find out what those do expressions are about.


On Thu, Sep 29, 2016 at 3:59 PM, Rick Waldron <waldron.rick at gmail.com>
wrote:

>
>
> 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
>



-- 
- Oli

Olivier Lalonde
http://www.syskall.com <-- connect with me!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160929/171d7fd8/attachment.html>


More information about the es-discuss mailing list