Will any new features be tied to constructors?

Domenic Denicola d at domenic.me
Wed Jul 1 00:54:42 UTC 2015


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?

```js
class CustomElement extends HTMLElement {
  [Element.init]() {
    // initialize private state
  }
}
```

Or would an actual constructor be required?

```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?

That question is, I think, what Anne is essentially asking when he asks about features that are "tied to constructors".


More information about the es-discuss mailing list