Hello,

Mark S. Miller wrote:
... 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.

It is written in class proposal:

- An efficient implementation. The private state should be allocated with the instance as part of a single allocation, and with no undue burden on the garbage collector.
- The ability to have private mutable state on publicly frozen objects.

Now it is the question, what does it say about "fixed shape". Does "fixed shape" mean no private can be added / deleted, but private properties themselves can be mutated? Or is it the weaker "the private space must be created and is not removable (in frozen object), but it is itself extensible and private properties are configurable and writable"?

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.

I have more thoughts on this, even the proposal how to make it work dynamically for non-const classes and "fixed" in const classes, but the answer to previous question seems important.

I presume the answer is "the latter", since "with no undue burden on the garbage collector" could be read as "if possible, blended in single object". But I would like to hear from you.

On Mon, Jan 9, 2012 at 8:33 AM, Herby Vojčík <he...@mailbox.sk
<mailto: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

--
     Cheers,
     --MarkM
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to