Proposal: throw null operator

Ranando King kingmph at gmail.com
Mon Feb 25 14:55:48 UTC 2019


Wasn't there a proposal that tend to allow for optional access of undefined
fields?
```js
let a = { foo:  "bar" };
let b = a.bar?.alpha; // b == undefined
```
The point, I believe, was to eliminate the field testing sometimes required
to find a nested sub-element, and simply return undefined if any branch
property wasn't an object.

To me, the OP here is asking for a very similar operation, causing the
"throw" action to be abandoned if the parameter doesn't exist, just as in
the above example, the [[GET]] operation would be abandoned and return
undefined.

On Sun, Feb 24, 2019 at 10:03 AM Isiah Meadows <isiahmeadows at gmail.com>
wrote:

> Not sure what the benefit is over just `if (value != null) throw value`,
> especially for this niche of a use case.
> On Sun, Feb 24, 2019 at 09:46 IdkGoodName Vilius <
> viliuskubilius416 at gmail.com> wrote:
>
>> I am proposing a syntatic sugar, which would check if throw value is not
>> null, or not undefined. It would make less typing and no if, for throw
>> statements. Syntax is simple. Here's an example of it:
>> ```js
>> throw? e
>> ```
>> This is basically equivalent to:
>> ```js
>> if(e !== null && e !== undefined) throw e
>> ```
>> What's the purpose of that? Well, in some node js modules, error as null,
>> or undefined is sometimes passed.
>> Example of that is:
>> ```js
>> const {exec} = require('child_process')
>> exec('...', {cwd: '...'}, (err, stdout, stderr) => {
>>     if(err !== null) throw err
>> })
>> ```
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free.
>> www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> <#m_2762807433789550130_m_-3729250569814530580_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> 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/20190225/d9472bc4/attachment.html>


More information about the es-discuss mailing list