Existential Operator / Null Propagation Operator (Laurentiu Macovei)

Laurentiu Macovei alonecomp at gmail.com
Thu Oct 29 20:55:30 UTC 2015


Javascript only works by `assumptions`, that the developer made at the time
the code was written than at runtime they will be the same (and not
changing by newly ESX).

So, it does NOT make sense to change the code that currently works
(expecting to throw error) so that would silently return `null` or
The behavior of the code would change and perhaps over 90% of the existing
libraries would not work anymore.

By wrapping code in `try` / `catch` is actually even worse - as adds way
extra code and extra penalty in performance.
Exceptions should not be used for anything but exception-edge cases.

So I presume the answer to your proposals is no and no.

And btw, the `?.` is already available in languages like [`Groovy`](
and proposed for [`c# 6.0`](
https://github.com/dotnet/roslyn/issues/5032#issuecomment-152303841). Even
[`Ruby`](https://bugs.ruby-lang.org/issues/11537#note-34) has a proposal
for the opposite one `.?` doing the same thing.

However as I have clarified above `var result = condition ? a?.b?.c?.d :
a?.x?.c?.d;` is way unclear / worse, in my opinion, than `var result =
condition ? a..b..c..d : a..x..c..d;`

Best Regards,
Laurenţiu Macovei

On Thu, Oct 29, 2015 at 8:30 PM, Ron Waldon <jokeyrhyme at gmail.com> wrote:

> Has anyone considering just making dot-property access return intermediate
> undefined or null values by default?
> Not having to introduce new syntax would be a bonus. I'm trying to think
> of existing code that this would break and can't think of any good examples.
> The only compatibility issue I have thought of so far is code that relies
> on an Error being thrown but also does not check the value:
> ```js
> let value;
> try { value = deep.deep.deep.prop; } catch (err) { /* ... */ }
> // use value without even a basic truthy test
> ```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151029/5d2e6cc3/attachment.html>

More information about the es-discuss mailing list