[w3c/webcomponents] Why doesn't Element.prototype.connectedCallback work? (#629)

Based on the extensible web manifesto, it seems that the following should work, but it doesn't:

```js
Element.prototype.connectedCallback = function() {

  console.log('connected', this.tagName)

}

document.body.innerHTML = "<div><h1>hello</h1></div>"
```

([fiddle](https://jsfiddle.net/9uo59n4d)).

Shouldn't we be able to do stuff like that, assuming APIs like the Custom Elements API help to explain native elements?

It'd be nice for library authors to be able to hook into the engine like that.

The current alternative way to hook into the engine like that is to use MutationObserver on all elements in the page, but the above solution

- is much cleaner
- performs better due to creation of a single function rather than who-knows-how-many MutationObservers
- behaves in a more predictable fashion because it is synchronous rather than asynchronous
- and is simply easier to work with than MutationObservers.

-- 
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/629

Received on Friday, 10 March 2017 19:09:45 UTC