Re: Defining a constructor for Element and friends

On 1/13/15 1:18 PM, Ryosuke Niwa wrote:
> I agree. It's unusual for a constructor of a super class to automatically instantiate an arbitrary subclass based on its arguments. And we usually solve that convenience problem by introducing a factory class/function.

While true, I do think there's a problem here.  Consider this:

   var element = new HTMLElement("somename");

OK, so the web author is not being very forward-compatible in that 
they're not using a tag name with a "-" in it.  But then they put it in 
the DOM and it acts just like a span, and they're happy with that.

Then we want to add a "somename" tag in the spec, and suddenly this JS 
throws.  This is a different order of breakage than what you get from 
just having new semantics for the "somename" tag.

In some cases, this is a problem no matter what; e.g. if "somename" is 
actually "img" or "canvas" then the layout is totally different too, not 
just the semantics.  But there are other cases where the layout is not 
that different from a vanilla inline.... though maybe we don't really 
plan to add any more of those?

In any case, it's a bit of a niggling worry for me because it can 
increase the chance that adding things to HTML breaks websites.

-Boris

Received on Tuesday, 13 January 2015 18:23:16 UTC