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?
I can see adding ?? and ??= (undefined-only, not undefined-or-null).
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 ??=?
/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;
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss