Created
March 21, 2014 20:31
-
-
Save laat/9695713 to your computer and use it in GitHub Desktop.
Ecmascript 6 Web Component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <link rel="import" href="x-foo.html"> | |
| </head> | |
| <body> | |
| <x-foo></x-foo> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template id="foo"> | |
| <span>foo</span> | |
| </template> | |
| <script> | |
| class XFoo extends HTMLElement { | |
| constructor() { | |
| let owner = document.currentScript.ownerDocument | |
| let template = owner.querySelector("#foo"); | |
| let clone = template.content.cloneNode(true); | |
| let root = this.createShadowRoot(); | |
| root.appendChild(clone); | |
| } | |
| foo() { | |
| console.log("foo!") | |
| } | |
| } | |
| XFoo.prototype.createdCallback = XFoo.prototype.constructor; | |
| XFoo = document.registerElement('x-foo', XFoo); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment