On Mon, Apr 15, 2013 at 8:57 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 4/14/13 5:35 PM, Rick Waldron wrote:
>
>> I have a better understanding of problem caused by these generated
>> HTML*Element constructors: they aren't constructable.
>>
>
> I'd like to understand what's meant here. I have a good understanding of
> how these constructors work in Gecko+SpiderMonkey, but I'm not sure what
> the lacking bit is, other than the fact that they have to create JS objects
> that have special state associated with them, so can't work with an object
> created by the [[Construct]] of a typical function.
>
> Is that what you're referring to, or something else?
Sorry, I should've been more specific. What I meant was that:
new HTMLButtonElement();
Doesn't construct an HTMLButtonElement, it throws with an "illegal
constructor" in Chrome and "HTMLButtonElement is not a constructor" in
Firefox (I'm sure this is the same across other browsers)
Which of course means that this is not possible even today:
function Smile() {
HTMLButtonElement.call(this);
this.textContent = ":)";
}
Smile.prototype = Object.create(HTMLButtonElement.prototype);
Since this doesn't work, the prototype method named "readyCallback" was
invented as a bolt-on stand-in for the actual [[Construct]]
Hopefully that clarifies?
Rick
PS. A bit of trivial... A long time ago some users requested that
jQuery facilitate a custom constructor; to make this work, John put the
actual constructor code in a prototype method called "init" and set that
method's prototype to jQuery's own prototype. The thing called
"readyCallback" is similar. For those that are interested, I created a gist
with a minimal illustration here: https://gist.github.com/rwldrn/5388544
>
>
> -Boris
>