On Thu, Jun 14, 2012 at 2:39 PM, Allen Wirfs-Brock <[email protected]>wrote:
> > snip > > I guess my concern is that there are significant existing subsystems where > null is distinguished from undefined or where null has a specifically > defined meaning that does not apply to undefined. For example: > > [[Prototype]] manipulation (Object.create, Object.getPrototypeOf, > __proto__) > RegExp exec and derived APIs > JSON stringify/parse > the DOM (WebIDL, provides lots of options vis [TreatUndefinedAs]] to > explicitly control the mapping of undefined) > More examples... event objects created by DOM APIs use null as the initial value of any data property whose value won't be known until an actual event has occurred. See: http://www.w3.org/TR/webmessaging/ http://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120614/ > snip > > 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. ||= 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; I realize that the strawman currently spells it "?:", consider this message an opposition to that. Rick > > Allen > > > > > > > > > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

