On Thu, May 19, 2011 at 12:02 PM, Brendan Eich <[email protected]> wrote:

> On May 19, 2011, at 11:55 AM, Mark S. Miller wrote:
>
> > I like Bob's "this.x" form best, especially when combined with your
> observation about default values.
>
> That's great -- if we want to shorthand harder, we can consider .x for
> this.x down the road.
>
>
> > The reason I prefer "this.x" rather than the terser ".x" or "@x" (even
> assuming away conflicts with other uses if "@"), is that I can imagine many
> programmers with ES < 6 experience, on seeing a "this.x" parameter for the
> first time, to be able to guess what it means.
>
> Sure.
>
> So I'm not sure you bought my argument that this means we don't need
> intiialisers for the public and private name declarations that are outside
> of the constructor head and body. And I don't want to twist Bob's arms. Let
> me know if this *does* relieve us from having to support initialisers
> evaluated per-construction yet declared outside the constructor.
>

Even without this, I am opposed to initializers outside the constructor for
the reason you already mentioned: confusion of execution time issues. If we
allowed

    class Stack {
      public items = [];
      //...
    }

some experienced JS programmers without Java experience would look at this
and sensibly expect the [] to be evaluated once per evaluation of the class
definition, leading all stacks to initialize their own "items" variable to a
shared initially empty list. For some purposes, this might even be useful.
Others would sensibly expect it to be evaluated once per constructor call.
Any resolution will give some sensible programmers rude surprises.

With the ability to say "this.x = 0" in the constructor parameters, this
choice becomes painless. But IMO the choice is necessary regardless.

-- 
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to