Last active
December 12, 2015 03:59
-
-
Save sjmiles/4711216 to your computer and use it in GitHub Desktop.
This file contains 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
ES6: | |
<element name="g-comp"> | |
<template> | |
... | |
</template> | |
<script> | |
// 'elementElement' would have to expose this.template | |
var template = this.template; | |
class Comp { | |
constructor: function() { | |
// super refers to Dimitri's generated constructor | |
super(); | |
var root = this.webkitCreateShadowRoot(); | |
root.appendChild(template.content.cloneNode(true)); | |
} | |
}; | |
this.lifecycle(Comp); | |
</script> | |
</element> | |
pre-ES6: | |
<element name="g-comp"> | |
<template> | |
... | |
</template> | |
<script> | |
// 'elementElement' would have to expose this.template | |
var template = this.template; | |
Comp = function() { | |
// 'super' | |
Comp.prototype.constructor(); | |
var root = this.webkitCreateShadowRoot(); | |
root.appendChild(template.content.cloneNode(true)); | |
}; | |
this.lifecycle(Comp); | |
</script> | |
</element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why? We can do firstElementChild or some other mechanism. No need to tightly couple it.
That looks wrong.
Comp.prototype.constructor === Comp
. For ES3 we need to hard code the reference to the super constructor. (Also, you lost this in that call.)