- From: Joe Pea <notifications@github.com>
- Date: Wed, 04 Apr 2018 17:20:46 +0000 (UTC)
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 4 April 2018 17:21:11 UTC
To make `HTMLELement` subclasses compatible with plain ES5-style constructors that call their super constructor with `.apply()` or `.call()`, the HTML engine should allow this: ```js function MyEl(...args) { const el = Reflect.construct(HTMLElement, args, new.target) el.__proto__ = this.__proto__ this.__proto__ = el // test: this.connectedCallback() // connected! console.log( this instanceof HTMLElement ) // true } MyEl.prototype = { __proto__: HTMLElement.prototype, constructor: MyEl, connectedCallback() { console.log(' ----- connected!') }, } MyEl.__proto__ = HTMLElement customElements.define('my-el', MyEl) const el = document.createElement('my-el') document.body.appendChild( el ) ``` But the engine gives this error: ``` Uncaught TypeError: Failed to construct 'CustomElement': The result must implement HTMLElement interface ``` But everything about the instance created from the `MyEl` constructor implements the interface! There's not a good reason it shouldn't work. The engine _could_ call `connectedCallback` if it just looks for the method which is there. Why exactly can't we be allowed to do things like this? -- 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-378678252
Received on Wednesday, 4 April 2018 17:21:11 UTC