tc39 / proposal-call-this

A proposal for a simple call-this operator in JavaScript.
https://tc39.es/proposal-call-this/
MIT License
121 stars 5 forks source link

Optional chaining form #15

Closed js-choi closed 3 years ago

js-choi commented 3 years ago

We probably should allow a.b?.::c(), like how we allow a.b?.c() and a.b?.(). I will amend the specification later.

ljharb commented 3 years ago

I'd expect a.b::c?.(), but since :: is not a property access, I'm not sure I understand why it'd need to be optional.

js-choi commented 3 years ago

Even when a is nullish, a::b will still create a non-nullish value: a bound function that will probably always throw a TypeError, depending on b’s usage of this. (In other words, null::fn is not itself nullish.)

So a::b?.() would not be useful to protect from a being possibly nullish, since a::b can never be nullish.

(And we’re trying to ensure that a::b(); is always equivalent to const x = a::b; x();.)