|
1 | 1 | <script> |
2 | | -(function() { |
3 | | - // Creates an object based in the HTML Element prototype |
4 | | - var element = Object.create(HTMLElement.prototype); |
| 2 | + // Creates MyElements extending HTML Element |
| 3 | + class MyElement extends HTMLElement { |
| 4 | + // Fires when an instance of the element is created or updated |
| 5 | + constructor() { |
| 6 | + super(); |
| 7 | + } |
5 | 8 |
|
6 | | - // Fires when an instance of the element is created |
7 | | - element.createdCallback = function() {}; |
| 9 | + // Fires when an instance was inserted into the document |
| 10 | + connectedCallback() { |
| 11 | + } |
8 | 12 |
|
9 | | - // Fires when an instance was inserted into the document |
10 | | - element.attachedCallback = function() {}; |
| 13 | + // Fires when an instance was removed from the document |
| 14 | + disconnectedCallback() { |
| 15 | + } |
11 | 16 |
|
12 | | - // Fires when an instance was removed from the document |
13 | | - element.detachedCallback = function() {}; |
| 17 | + attributeChangedCallback(attrName, oldVal, newVal) { |
| 18 | + } |
14 | 19 |
|
15 | | - // Fires when an attribute was added, removed, or updated |
16 | | - element.attributeChangedCallback = function(attr, oldVal, newVal) {}; |
| 20 | + // Fires when an attribute was added, removed, or updated |
| 21 | + adoptedCallback() { |
| 22 | + } |
| 23 | + } |
17 | 24 |
|
18 | 25 | // Registers custom element |
19 | | - document.registerElement('my-element', { |
20 | | - prototype: element |
21 | | - }); |
22 | | -}()); |
| 26 | + window.customElements.define('my-element', MyElement); |
23 | 27 | </script> |
0 commit comments