Will any new features be tied to constructors?

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Jul 1 02:45:50 UTC 2015


On Jun 30, 2015, at 5:54 PM, Domenic Denicola wrote:

> Allen, Kevin: I think the key question about private state and how it interacts with Anne's question is this.
> 
> Given a base class looking roughly like
> 
> ```js
> class HTMLElement extends Element {
>  constructor(...) {
>    super(...);
>    // ...other stuff...
>    this[Element.init]();
>  }
> }
> ```
> 
> then, will the following work?

no, not in the way that I believe you intend




> 
> ```js
> class CustomElement extends HTMLElement {
>  [Element.init]() {
>    // initialize private state
>  }
> }
> ```
> 
> Or would an actual constructor be required?

yes

> 
> ```js
> class CustomElement extends HTMLElement {
>  constructor(...args) {
>    super(...args);
>    // initialize private state
>  }
> }
> ```
> 
> Stated another way, which might be a bit stronger: will it be *lexically* required that private state initialization be within the constructor, or will it only be *temporally* required?

It isn't that  subclass specific private state "initialization" must be performed in the constructors. In the design that Kevin and I have been working on,  the total number of private state slots (and some meta data for each one) must be knowable and fixed when an object is allocated   (in other words, private slots cannot be added to an object after it is initially allocated).  Those slots can be "initialized" in an application manner at any time and in any manner.

Allen


More information about the es-discuss mailing list