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

* Rick Waldron wrote:
>On Tue, Apr 16, 2013 at 9:51 PM, Bjoern Hoehrmann <derhoermi@gmx.net> wrote:
>> * Rick Waldron wrote:
>> >If I want to make a new button to put in the document, the first thing my
>> >JS programming experience tells me:
>> >
>> >  new Button();
>>
>> And if you read code like `new A();` your programming experience would
>> probably tell you that you are looking at machine-generated code.
>
>I'm not sure what your own experience is, but I completely disagree.

I think it is easy to agree with your analogy above. My purpose was to
offer reasons why it is a bad analogy that does not hold when you take
into account various other constraints and problems. For the specific
example, I think it is unreasonable for humans to define single-letter
global names in a shared namespace, and even more unreasonable for some
standards organisation to do so. With `A` in particular, there is also
the problem that `<a>` might be "HTML" or it might be "SVG", so mapping
`new Button()` to `<button>` is not an analogy that works all the time.

>> And between
>>
>>   new HTMLButtonElement();
>>
>> and
>>
>>   new Element('button');
>>
>> I don't see why anyone would want the former in an environment where you
>> cannot rely on `HTMLHGroupElement` existing (the `hgroup` element had
>> been proposed, and is currently withdrawn, or not, depending on where
>> you get your news from).
>
>The latter is indeed a much nicer to look at then the former, but Element
>is higher then HTMLButtonElement, so how would Element know that an
>argument with the value "button" indicated that a HTMLButtonElement should
>be allocated and initialized? Some kind of nodeName => constructor map, I
>suppose...? (thinking out loud)

As above, `new Element('a')` does not indicate whether you want a HTML
`<a>` element or a a SVG `<a>` element. When parsing strings there is,
in essence, such a map, but there is more context than just the name.
That may well be a design error, perhaps "HTML" and "SVG" should never
have been separate namespaces.

>> in contrast to, if you will,
>>
>>   var button = new Button();
>>   button.ownerDocument.example(...);
>
>I would expect this:
>
>  var button = new HTMLButtonElement();
>  button.ownerDocument === null; // true
>
>  document.body.appendChild(button);
>
>  button.ownerDocument === document; // true

Indeed. But browser vendors do not think like that.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Thursday, 18 April 2013 02:35:09 UTC