Re: Why can't we just use constructor instead of createdCallback?

On Dec 6, 2013, at 7:37 AM, Erik Arvidsson <arv@chromium.org> wrote:

> On Fri, Dec 6, 2013 at 2:33 AM, Ryosuke Niwa <rniwa@apple.com> wrote:
> It appears to me that we should definitely have a good answer for this question before the specification reaches CR
> given that the definition of ES6 classes is pretty stable at this point.
> 
> ES6 classes do not introduce any new semantics over ES5. However I do agree that we need to think about user ergonomics here. If we cannot use ES6 class syntax to do custom elements we have failed. What we have now is OK but not perfect.
> 
> Here is how you can use class syntax today
> 
> ```js
> class MyElement extends HTMLElement {
>   createdCallback() {
>     console.log("I'm not a real boy");
>   }
> }
> MyElement = document.create('my-element, MyElement);
> 
> // or
> 
> var MyElement = document.create('my-element, class extends HTMLElement {
>   createdCallback() {
>     console.log("I'm not a real boy");
>   }
> });
> ```

What if that class definition had constructor() in it?  It would be called?  If so, when?

> 1. The parser does not know that it needs to use MyElement.@@create to create the JS objects when it sees a <my-element>.
> 2. No callbacks for enteredView, leftView and attributeChanged.
> 3. It depend on the magic of document.createElement which is circular. A better way would be to do `super('my-element')` or something like that.
> 
> I wish we could resolve these remaining issues.

In fact, fixing these issues is a requirement for us.

- R. Niwa

Received on Friday, 6 December 2013 20:29:12 UTC