This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
DOM has a bunch of element constructors that take parameters. `new Image(src)` for example. Custom elements fail in this regard. The following should just work. ```js class MyElement extends HTMLElement { constructor(text) { this.textContent = text; } } MyElement = document.register('my-element', MyElement); new MyElement('Hi'); ```
I think this should be addressed in Level 2 of the Custom Elements spec, or in a related spec. Chrome is not in a position to implement this now. Does ES6 make it possible to detect whether a function is a "class" or has a constructor? I believe this is a simple matter of specifying that, for such functions, the generated constructor passes arguments to the argument's constructor. It would be useful for someone with deep familiarity with ES6 to explain in what other ways the generated constructor should be configured.
> Does ES6 make it possible to detect whether a function is a "class" or has a constructor? There is no difference between a class and a function. The only way to tell the difference is in what Function.prototype.toString would return. http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tostring The constructor is always the function representing the class. ```js class C {} assert(C === C.prototype.constructor); class C2 { constructor() {} } assert(C2 === C2.prototype.constructor); ``` Just like `Date === Date.prototype.contstructor` and `HTMLElement === HTMLElement.prototype.constructor`. When writing "classes" using ES3/ES5 libraries such as Closure, Backbone, Ember, Ext.js, YUI etc they will set up the prototype.constructor so that this equivalence also holds.
(In reply to Erik Arvidsson from comment #2) > > Does ES6 make it possible to detect whether a function is a "class" or has a constructor? > > There is no difference between a class and a function. OK. So it makes sense to pass the parameters through in the case where the second argument to register is a function.
Addressed in https://github.com/w3c/webcomponents/commit/03f1382155de885c63cca9cdd78fdf34c72fa495