- From: <bugzilla@jessica.w3.org>
- Date: Fri, 06 Dec 2013 15:58:32 +0000
- To: public-webapps-bugzilla@w3.org
https://www.w3.org/Bugs/Public/show_bug.cgi?id=24020
Bug ID: 24020
Summary: [Custom]: A tag name should be associated with the
constructor and not the prototype
Product: WebAppsWG
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Component Model
Assignee: dglazkov@chromium.org
Reporter: arv@chromium.org
QA Contact: public-webapps-bugzilla@w3.org
Blocks: 14968
Given how WebIdl works with interfaces that are realized as ES constructor
functions with a prototype we should associate the tag name with a function and
not the prototype.
class MyElement extends HTMLElement {}
associate('my-element, MyElement)
When an element is created for 'my-element' we find the registered Function and
call its @@create. Here is how HTMLElement @@create is implemented.
var constructorToNameMap = new WeakMap();
function associate(name, constr) {
constructorToNameMap.set(constr, name);
}
HTMLElement[Symbol.create] = function() {
var name = constructorToNameMap.get(this);
if (!name)
throw new TypeError('Illegal constructor');
// $Internal_createElementWithName(name);
return document.createElement(name);
};
The common case is that people do not override @@create so we do not need to
run any user code to create an instance. When the user does a `new MyElement`
we do run the constructor, just like for all other js constructors.
--
You are receiving this mail because:
You are the QA Contact for the bug.
Received on Friday, 6 December 2013 15:58:34 UTC