I noted some open issues on "Classes with Trait Composition"

Brendan Eich brendan at mozilla.com
Thu May 19 17:40:03 PDT 2011

Hi Bob, a few more thoughts/questions/distinctions.

On May 19, 2011, at 1:08 PM, Bob Nystrom wrote:

> On Thu, May 19, 2011 at 11:47 AM, Brendan Eich <brendan at mozilla.com> wrote:
> Here's another question: how many property initializations could be done straight from the parameter of the same name?
> Of the 88 fields I looked at, 10 were straight copies of a constructor argument. Another 4 are copies with an "if undefined then use this default instead" check.

??=, check (http://wiki.ecmascript.org/doku.php?id=strawman:default_operator -- this is going for Harmony gold next week!).

> That may be biased a bit low since most of the code I looked at is UI widget-like stuff.

Also, Closure library, right? Opinions vary on the style used there.

Not taking sides, just asking for you lurkers who use other libraries to do similar counting exercises with those libraries, if you all can spare the time. Thanks.

> Code that's more data-model oriented would probably have more cases where a class is just wrapping a bunch of arguments.
> Apart from the desire to declare per-instance property names, do we really need default values if the constructor author could write default parameter values?
> class Point {
>   constructor(x = 0, y = 0) {
>     this.x = x;
>     this.y = y;
>   }
>  ...
> }
> That covers a different (though useful!) case. This would be helpful for the 4 cases above where a field is initialized to a constructor argument if given, or to a default value if not.

Hmm, parameter default values != the ??= operator, because while missing actual parameters are undefined, and ??= selects the right-hand side if the left-hand side evaluates to undefined, you can pass undefined followed by other actual parameters to trigger ??=-based defaulting instead of missing (trailing actual) parameter defaulting.

Are the 4 cases all such that the calls to the constructors leave off trailing arguments, or do they pass undefined? Or perhaps they pass other falsy default values, in which case ||= not ??= (and again not parameter default values) could help?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110519/dfb5d79e/attachment.html>

More information about the es-discuss mailing list