Skip to content

Instantly share code, notes, and snippets.

@sjmiles
Last active December 12, 2015 03:59
Show Gist options
  • Save sjmiles/4711216 to your computer and use it in GitHub Desktop.
Save sjmiles/4711216 to your computer and use it in GitHub Desktop.
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>
@arv
Copy link

arv commented Feb 5, 2013

// 'elementElement' would have to expose this.template

Why? We can do firstElementChild or some other mechanism. No need to tightly couple it.

// 'super'
Comp.prototype.constructor();

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment