Re: [w3c/webcomponents] Non-class based example of customElement.define() (#587)

> That just sounds like a bug in Electron...

Turns out I was goofing up. Load order is important. The following doesn't work:

```js
const ES5Element = function() {}
Reflect.construct(HTMLElement, [], ES5Element) // Uncaught TypeError: Illegal constructor
customElements.define('es5-element', ES5Element)
```

while the following does:

```js
const ES5Element = function() {}
customElements.define('es5-element', ES5Element)
Reflect.construct(HTMLElement, [], ES5Element)
```

Interesting you thought it may have been an electron bug, which shows the situation can be confusing. 

Perhaps the error messages from the browsers could be more helpful.

For example `Uncaught TypeError: Illegal constructor, HTMLElement. Did you forget to define a custom element before calling it with 'new'?` instead of just `Uncaught TypeError: Illegal constructor`.

That may have prevented my confusion.

---

The reason I thought it worked in other browsers besides Electron was because I was either writing markup, or using `document.createElement` to create the elements, which works and the engine can upgrade them later. I was using `new` in Electron before defining the elements.

Would it be possible for the engine to special-case `new MyElement` to behave similarly to `document.createElement`?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/587#issuecomment-445448955

Received on Saturday, 8 December 2018 10:28:25 UTC