||= is much needed?
dherman at mozilla.com
Fri Jun 15 12:33:02 PDT 2012
On Jun 14, 2012, at 1:45 PM, Brendan Eich wrote:
> I can see adding ?? and ??= (undefined-only, not undefined-or-null).
I think ?? is the highest priority.
> Is ||= really worth it? It would not assign if the left side is truthy, but perhaps no one will mind.
> Given ||= is there any oxygen left in the room for ??=?
??= is strictly less error-prone than ||= so I can't see why we would favor ||= if we were choosing just one.
As I see it, the biggest issue with ??= and ||= is that -- unlike other compound assignment forms -- they are short-circuiting. All the existing compound assignment forms evaluate both sides no matter what. IIRC, back in the ES4 days, this is why we rejected ||=.
I'm still not against it, though. It's obvious what it means. It's obviously useful.
So I favor ?? as well as both ||= and ??=.
As for null, I can see how there's confusion about whether to use null vs undefined, and so I can see why CoffeeScript would just try to blur the distinction between them. But I think by sticking to the simpler semantics it will help clarify the distinction. The JS semantics currently treats only undefined as "no value" and it would continue to do so.
More information about the es-discuss