Elements are rather curious web platform objects in that they are instantiated based on their name (and namespace). <a>
creates an HTMLAnchorElement
object. So does document.createElement("a")
. Elements are also identified by their name, more so than by their class. Well written code branches on localName
(not instanceof HTMLAnchorElement
, which has cross-Realm issues to boot). Selectors match based on element names. Ergo, there is a lot of code assuming that an element whose name is input
and namespace is http://www.w3.org/1999/xhtml
, is also an instance of an HTMLInputElement
class.
That is further compounded by only an instance of an HTMLInputElement
class having the correct internal slots (as explained in Web platform and JavaScript). An element named input
with namespace http://www.w3.org/1999/xhtml
would cause havoc in browsers (and specifications) if its object was not an instance of an HTMLInputElement
class.
These invariants start becoming problematic when introducing constructors and allowing for subclassing. Domenic started a GitHub repository element-constructors to tease them out. If you are interested in how we bring the DOM and JavaScript together I recommend participating.