||= is much needed?
Rick Waldron
waldron.rick at gmail.com
Thu Jun 14 14:16:50 PDT 2012
On Thu, Jun 14, 2012 at 3:45 PM, Brendan Eich <brendan at mozilla.com> wrote:
> Rick Waldron wrote:
>
>>
>> One way to have it both ways is to have multiple syntactic forms
>> for default value initializers. EG:
>>
>> function f(a = 1, b ??= 2, c ||= 3) { } //assuming ??= is
>> undefined or null defaulting guard and ||= is falsy
>>
>> I'm not particularly convinced that the additional complexity is
>> warranted but it would place the choice into ES programmers hands
>> rather us trying to anticipate the typical intent and
>> disadvantaging the untypical.
>>
>>
>> I agree with this entirely.
>>
>
> Including the part where Allen is not convinced to add all these forms?
>
Yes.
...But it felt useful to note that ||= would compliment || and immediately
understood by devs
>
> I can see adding ?? and ??= (undefined-only, not undefined-or-null).
>
Yes, absolutely.
>
> Is ||= really worth it? It would not assign if the left side is truthy,
> but perhaps no one will mind.
That makes complete sense to me, but again - it might not be worth adding,
because a = b || c isn't that painful.
>
> Given ||= is there any oxygen left in the room for ??=?
Right now, I believe the whole set compliment the current language and its
operators nicely - but if it came down to one or the other, I would prefer
seeing the new addition of ?? and ??=
Rick
>
>
> /be
>
>
>> ||= is complementary to || and makes sense - developers will embrace this
>> as is.
>>
>>
>> ?? and ??= seem like "something is unknown" and unknown things can
>> otherwise be described as "undefined". Definitively, |null| is intentional
>> -- which implies something "known" and therefore cannot qualify as
>> "undefined". I think sticking to undefined will help to fix the abused "==
>> null" patterns in extant code (I'm thinking in the long term of course)
>>
>> If null testing is needed:
>>
>> a = a != null ? a : default;
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120614/c2633256/attachment.html>
More information about the es-discuss
mailing list