Skip to content

Instantly share code, notes, and snippets.

@arv
Created June 1, 2012 22:16
Show Gist options
  • Save arv/2855456 to your computer and use it in GitHub Desktop.
Save arv/2855456 to your computer and use it in GitHub Desktop.
Custom Elements
// And in browsers that support __proto__:
document.register('x-foo', {
extends: 'p',
prototype: {
__proto__: HTMLParagraphElement.prototype,
get foo() { return 'foo'; }
}
})
var p = Object.create(HTMLParagraphElement.prototype);
p.hello = function() { alert('world'); };
document.register('x-foo', {
extends: 'p',
prototype: p
})
// And in browsers that support __proto__:
document.register('x-foo', {
extends: 'p',
prototype: {
__proto__: HTMLParagraphElement.prototype,
get foo() { return 'foo'; }
}
})
document.register('x-foo', {
extends: 'p',
prototype: Object.create(HTMLParagraphElement.prototype, {
foo: {
get: function() { return foo; },
enumerable: true,
configurable: true
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment