Hi Herby, I looked back over the class proposal and found that it indeed leaves this case ambiguous, as you point out. We have also not discussed it in committee or even in separate side discussions in which I participated. I don't have strong feelings about this for non-const classes. For const classes, I think privates should always be declared in the constructor. I would like to be able to always allocate instances of const classes of fixed "shape", i.e., non-configurable / non-extensible, so that users don't have to worry about whether they've enabled the resulting optimizations or whether they have uncaught spelling errors.
For consistency, perhaps we should make similar requirements for privates of non-const classes, but this isn't clear. If you have some arguments one way or another, please post. Thanks. On Mon, Jan 9, 2012 at 8:33 AM, Herby Vojčík <he...@mailbox.sk> wrote: > Hello, > > the current class proposal (as I read it) specifies that the private block > is created by first 'private foo[ = "bar"];' in the constructor. The > question is, what is constructor does not contain any private declarations, > but uses private, like this: > > class Coutner { > constructor () { > this.reset(); > } > > increment () { > private(this).c++; > } > > reset () { > private(this).c = 0; > } > > get count () { > return private(this).c; > } > } > > The reset method is part of the API. Conveniently, it resets the state of > the object to the initial state, so constructor is calling it. > The question is: does private(this) create the private storage block in > this case? > > Herby > ______________________________**_________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss> > -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss