You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 13, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+18-9Lines changed: 18 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Custom elements are still elements. We can create, use, manipulate, and compose
13
13
### Basic usage
14
14
15
15
As with any element, custom elements can be created in JavaScript or declared.
16
-
**Their name must always contain a dash (-).**
16
+
**Custom element names must always contain a dash (-).**
17
17
18
18
#### Element registration
19
19
@@ -89,13 +89,13 @@ declare the type using the `extends` option when calling `document.register()`:
89
89
90
90
Example extending `button`:
91
91
92
-
var XFooPrototype = Object.create(HTMLButtonElement.prototype);
93
-
XFooPrototype.readyCallback = function() {
94
-
this.textContent = "I'm an x-foo!";
92
+
var XFooButtonPrototype = Object.create(HTMLButtonElement.prototype);
93
+
XFooButtonPrototype.readyCallback = function() {
94
+
this.textContent = "I'm an x-foo button!";
95
95
};
96
96
97
-
var XFoo = document.register('x-foo', {
98
-
prototype: XFooPrototype,
97
+
var XFooButton = document.register('x-foo-button', {
98
+
prototype: XFooButtonPrototype,
99
99
extends: 'button'
100
100
});
101
101
@@ -106,13 +106,22 @@ standard DOM elements:
106
106
107
107
<x-foo></x-foo>
108
108
109
-
In the declarative and `document.register()` examples above, `XFoo` was defined as the new element's constructor. Browser limitations require that we supply the constructor while you supply the prototype. Use the `readyCallback` to do initialization work that might otherwise be in the constructor.
109
+
If you've used `extends` to create a custom element that derives from an existing DOM element
110
+
(e.g. something other than `HTMLElement`), use the `is` syntax:
111
+
112
+
<button is="x-foo-button"></button>
113
+
114
+
In the declarative and `document.register()` example above, `XFoo` was defined as the new element's constructor.
115
+
This can also be used to create an instance:
110
116
111
117
var xFoo = new XFoo();
112
118
document.body.appendChild(xFoo);
113
119
114
-
var xFoo2 = document.createElement('x-foo');
115
-
xFoo2.foo(); // "foo() called"
120
+
var xFooButton = document.createElement('button', 'x-foo-button');
121
+
xFooButton.foo(); // "foo() called"
122
+
123
+
Browser limitations require that we supply the constructor while you supply the `prototype`.
124
+
Use the `readyCallback` to do initialization work that might otherwise be in a constructor.
0 commit comments