From the custom elements page, I see that to extend an element you do:
var XFooButtonPrototype = Object.create(HTMLButtonElement.prototype);
XFooButtonPrototype.createdCallback = function() {
this.textContent = "I'm an x-foo button!";
};
var XFooButton = document.registerElement('x-foo-button', {
prototype: XFooButtonPrototype,
extends: 'button'
});
Then later in the guide it says that you can make an element by writing either:
<x-foo></x-foo>
Or:
<button is="x-foo-button"></button>
Questions:
Why is it important to specify
extends: 'button'when the element is obviously_ inheriting fromHTMLButtonElement(since it hasHTMLButtonElement.prototypein its proto chain)How is the link between
buttonandx-foo-buttonestablished? Doesx-foo-buttonbecome a possible option of button in terms ofis="x-foo-button"thanks to thatextends: 'button'? What happens "internally", so to speak?Why would you pick
<button is="x-foo-button"></button>over<x-foo></x-foo>...?
[ADDENDUM]
Polymer saves us from this duplication:
MyInput = Polymer({
is: 'my-input',
extends: 'input',
created: function() {
this.style.border = '1px solid red';
}
});
If extends is there, Polymer will put the right prototype in the chain with Object.getPrototypeOf(document.createElement(tag));.
So, corollary question:
- Why the duplication in the first place? If there is an
extends, shouldn't the browser automatically do this?