-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathminimal-es5-setup.html
43 lines (35 loc) · 1.31 KB
/
minimal-es5-setup.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Web components example</title>
</head>
<body>
<script src="https://unpkg.com/[email protected]/es6-shim.min.js"></script>
<script src="https://unpkg.com/@webcomponents/custom-elements"></script>
<script>
// Works in IE11+
function LegacyElement() {
return Reflect.construct(HTMLElement, [], this.constructor);
}
LegacyElement.prototype = Object.create(HTMLElement.prototype);
LegacyElement.prototype.constructor = LegacyElement;
LegacyElement.prototype.connectedCallback = function () {
this.appendChild(document.createTextNode("A little rusty!"));
};
Object.setPrototypeOf(LegacyElement, HTMLElement);
customElements.define("legacy-element", LegacyElement);
</script>
<script type="module">
// Only for modern browsers
customElements.define("modern-element", class extends HTMLElement {
connectedCallback() {
this.appendChild(document.createTextNode("Shiny!"));
}
});
</script>
<!-- Note that custom elements can not be self-closing -->
<legacy-element></legacy-element>
<modern-element></modern-element>
</body>
</html>