||= is much needed?

T.J. Crowder tj at crowdersoftware.com
Thu Jun 14 14:45:18 PDT 2012

On 14 June 2012 22:38, John Tamplin <jat at google.com> wrote:

> On Thu, Jun 14, 2012 at 5:32 PM, T.J. Crowder <tj at crowdersoftware.com>wrote:
>>> Is ||= really worth it? It would not assign if the left side is truthy,
>>> but perhaps no one will mind.
>> Nice-to-have. The fact it doesn't assign if the left side is truthy is
>> the only reason for having it, surely?
> Plus not even evaluating the RHS if the LHS is truthy -- useful if the
> default is an expensive calculation.

Right, but `a = a || b` doesn't evaluate `b` if `a` is truthy, either. What I
meant was, if we have `a ??= b`, and of course we already have `a = a ||
b`, the only reason for having `a ||= b` is that it doesn't assign if `a`
is truthy.

-- T.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120614/8a4fe27e/attachment.html>

More information about the es-discuss mailing list