W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2015

Re: Defining a constructor for Element and friends

From: Boris Zbarsky <bzbarsky@mit.edu>
Date: Tue, 13 Jan 2015 13:22:43 -0500
Message-ID: <54B56273.4020501@mit.edu>
To: Ryosuke Niwa <rniwa@apple.com>, Domenic Denicola <d@domenic.me>
CC: Anne van Kesteren <annevk@annevk.nl>, WebApps WG <public-webapps@w3.org>, "www-dom@w3.org" <www-dom@w3.org>
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:14 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:25 UTC