Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Jun 7, 2013
1 parent e34dc42 commit bf36b5a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ declare the type using the `extends` option when calling `document.register()`:

Example extending `button`:

var XFooPrototype = Object.create(HTMLButtonElement.prototype);
XFooPrototype.readyCallback = function() {
this.textContent = "I'm an x-foo!";
var XFooButtonPrototype = Object.create(HTMLButtonElement.prototype);
XFooButtonPrototype.readyCallback = function() {
this.textContent = "I'm an x-foo button!";
};

var XFoo = document.register('x-foo', {
prototype: XFooPrototype,
var XFooButton = document.register('x-foo-button', {
prototype: XFooButtonPrototype,
extends: 'button'
});

Expand All @@ -106,13 +106,22 @@ standard DOM elements:

<x-foo></x-foo>

In the declarative and `document.register()` examples above, `XFoo` was defined as the new element's constructor. Browser limitations require that we supply the constructor while you supply the prototype. Use the `readyCallback` to do initialization work that might otherwise be in the constructor.
If you've used `extends` to create a custom element that derives from an existing DOM element
(e.g. something other than `HTMLElement`), use the `is` syntax:

<button is="x-foo-button"></button>

In the declarative and `document.register()` example above, `XFoo` was defined as the new element's constructor.
THis can also be used to create an instance:

var xFoo = new XFoo();
document.body.appendChild(xFoo);

var xFoo2 = document.createElement('x-foo');
xFoo2.foo(); // "foo() called"
var xFooButton = document.createElement('button', 'x-foo-button');
xFooButton.foo(); // "foo() called"

Browser limitations require that we supply the constructor while you supply the `prototype`.
Use the `readyCallback` to do initialization work that might otherwise be in a constructor.

## Polyfill details

Expand Down

0 comments on commit bf36b5a

Please sign in to comment.