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

* Rick Waldron wrote:
>Of course, but we'd also eat scraps from the trash if that was the only
>edible food left on earth. document.createElement() is and has always been
>"the wrong way"—the numbers shown in those graphs are grossly skewed by a
>complete lack of any real alternative.
>
>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. And if
you read `new Time();` you would have no idea whether this creates some
`new Date();`-like object, or throw an exception because the browser you
try to run that code on does not support the `<time />` element "yet" or
"anymore" (the element was proposed, withdrawn, and then proposed again)
and if it's something like

  var font = new Font("Arial 12pt");
  canvas.drawText("Hello World!", font);

The idea that you are constructing `<font />` elements probably wouldn't
cross your mind much. 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). Furthermore, there actually are a number of
dependencies to take into account, like in

  var agent = new XMLHttpRequest();
  ...
  agent.open('GET', 'example');

Should that fail because the code does not say where to get `example`
from, or should it succeed by picking up some base reference magically
from the environment (and which one, is `example` relative to from the
script code, or the document the code has been transcluded into, and
when is that decision made as code moves across global objects, and so
on)? Same question for `new Element('a')`, if the object exposes some
method to obtain the "absolute" value of the `href` attribute in some
way.

>But I live in the "bad old days" (assuming my children won't have to use
>garbage APIs to program the web) and my reality is still here:
>
>  document.createElement("button");

That very clearly binds the return value to `document` so you actually
can do

  var button = document.createElement("button");
  ...
  button.ownerDocument.example(...);

in contrast to, if you will,

  var button = new Button();
  button.ownerDocument.example(...);

where `button.ownerDocument` could only have a Document value if there
is some dependency on "global state" that your own code did not create.
I would expect that code to fail because the ownerDocument has not been
specified, and even if I would expect that particular code to succeed,
I would be unable to tell what would happen if `example` was invoked in
some other way, especially when `example` comes from another global.
-- 
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 Wednesday, 17 April 2013 01:52:00 UTC