Existential operator (was: ||= is much needed?)

Domenic Denicola domenic at domenicdenicola.com
Tue Jun 19 11:24:13 PDT 2012

What struck me from Jeremy's explanation was the uniformity of CoffeeScript's ? operator (modulo the small issue he mentioned for function calls). It seems to combine the currently-strawman'ed ??/??= and ?. into one very simple semantic.

What about adopting ?? as CoffeeScript's ? operator? Would this solve the lookahead problems? So you could do


This would unfortunately imply, for uniformity, that

object ?? other
object ??= other

become null + undefined tests instead of just undefined. But that might be worth paying.

For the record that leaves object?? as the only unimplemented CoffeeScript counterpart.

From: es-discuss-bounces at mozilla.org [es-discuss-bounces at mozilla.org] on behalf of Brendan Eich [brendan at mozilla.org]
Sent: Tuesday, June 19, 2012 14:08
To: Jeremy Ashkenas
Cc: es-discuss
Subject: Re: Existential operator (was: ||= is much needed?)

Jeremy Ashkenas wrote:
> Everywhere else in the language, `?` means existence (not null or
> undefined) -- but when used to call a function, the check ensures that
> the value is callable as well. In a DWIM sense, this makes sense,
> because the only things you'd ever want to try to call in JavaScript
> must be callable ... but I think it's strange that the meaning of
> "existence" alters itself just for this use case. I opened a ticket
> talking about rolling it back to "null or undefined" semantics here:
> https://github.com/jashkenas/coffee-script/issues/2315

Apart from people misreading the proposal in this issue, it does seem to
be removing a bit of utility, but perhaps that's not actually used? Do
CS users try to ?(-invoke a maybe-function that is sometimes neither
null nor undefined nor typeof-type "function", but rather something that
coerces to object?

The way to get ?( into JS is by a longer spelling:


Pretty ugly, but it puts the ? magic right where the maybe-test belongs.


es-discuss mailing list
es-discuss at mozilla.org

More information about the es-discuss mailing list