Re: [webcomponents]: Of weird script elements and Benadryl

On Mon, Apr 15, 2013 at 11:59 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 4/15/13 10:45 AM, Rick Waldron wrote:
>
>> 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)
>>
>
> Oh, I see.  That's not anything inherent, for what it's worth; making this
> particular case work would be <10 lines of code.  Less on a per-element
> basis if we want to do this for most elements.
>
>
>  function Smile() {
>>    HTMLButtonElement.call(this);
>>    this.textContent = ":)";
>> }
>>
>> Smile.prototype = Object.create(**HTMLButtonElement.prototype);
>>
>
> Ah, so... This would not work even if "new HTMLButtonElement" worked,
> right?


I guess I assumed this would work if new HTMLButtonElement() could
construct things


> In particular, if HTMLButtonElement were actually something that could
> construct things in Gecko, it would still ignore its argument when called
> and always creates a new object.  You can see the behavior with something
> like XMLHttpRequest if you want.
>

What I was expecting the above to produce is a constructor capable of
something like this:

  var smile = new Smile();
  smile.nodeType === 1;
  smile.outerHTML === "<button>:)</button>"; // true
  // (and so forth)
  document.body.appendChild(smile);

results in something like this: http://gul.ly/de0


Rick



>
>  Hopefully that clarifies?
>>
>
> Somewhat.  Trying to understand what things we really need to support here
> and in what ways, long-term...
>
> -Boris
>

Received on Monday, 15 April 2013 19:47:27 UTC