Re: Defining a constructor for Element and friends

Ryosuke Niwa <[email protected]>
Newsgroups gmane.comp.web.dom.general,gmane.org.w3c.webapps
Message-ID <[email protected]>
> On Jan 13, 2015, at 10:22 AM, Boris Zbarsky <[email protected]> wrote:
> 
>> 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.

Shouldn't we throw in this case because the concert type of "somename" is HTMLUnknownElement?

> 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 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.

I think if we threw an exception on every attempt to create an element with a name without "-" (as they're HTMLUnknownElement anyway), then we can probably mitigate this forward compatibility issue.

Hopefully, authors won't be creating HTMLUnknownElement all that often...

- R. Niwa
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.