Proposing a conditional assignment (or equals) operator

Claude Pache claude.pache at gmail.com
Tue May 10 08:21:49 UTC 2016


> Le 10 mai 2016 à 09:44, G. Kay Lee <balancetraveller+es-discuss at gmail.com> a écrit :
> 
> 
> Can't remember any instance where I've written something like `x = x || {}` after the introduction of Default Parameters in ES6, so I don't see any chance for me writing something like `x ||= {}` even if this thing somehow makes its way in.

Some people do have use cases despite default arguments, see e.g. https://esdiscuss.org/topic/is-much-needed#content-4 <https://esdiscuss.org/topic/is-much-needed#content-4>

> 
> The thing is, it's far more common to encounter codes like `x = y || {}`, and then a new Default Operator would make sense due to the issue with falsy values. So I'd throw my support behind an authentic Default Operator proposal like `x = y ?? {}` (http://wiki.ecmascript.org/doku.php?id=strawman:default_operator <http://wiki.ecmascript.org/doku.php?id=strawman:default_operator>). But definitely not `||=`.
> 

Agree. I wonder why people keep to reclaim a `||=` operator (with semantics inspired from binary `||`), when their use cases generally show that `??=` is more appropriate (with approximate semantics of: `if (a === undefined) a = b;`).

—Claude
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160510/16c67622/attachment.html>


More information about the es-discuss mailing list