问题
As I know,getElementsByName
is a function defined in HTMLDocument
,and HTMLDocument
inherits from Document
,and Document
inherits from Node
.
So why I can see Document.prototype.getElementsByName
in Chrome but not Firefox?Does not Chrome implement DOM2 spec?
回答1:
Does not Chrome implement DOM2 spec?
Yeah, probably not. I'd guess they at least implement DOM 3, if not a more current version :-)
However, those don't define a getElementsByName
either. So how did they get this? It is actually specified in HTML5 (WHATWG/W3) on the Document
partial interface:
The DOM specification defines a Document interface, which this [HTML5] specification extends significantly […]
And at http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom I found the note
Because the HTMLDocument interface is now obtained using binding-specific casting methods instead of simply being the primary interface of the document object, it is no longer defined as inheriting from Document.
So the specification details of these interfaces are still in progress, and varying. Notice that browsers are not even supposed to export any kind of WebIDL does.DocumentPrototype
- the specs do only define interfaces, not the exact EcmaScript binding representation of them.
So Chrome does follow the newer specs (but still has some HTMLDocument
?), while Firefox implements an older version. However, it only really matters that these methods do exist on every window.document
- not how they got there :-)
来源:https://stackoverflow.com/questions/21771768/why-does-document-prototype-getelementsbyname-exist-in-chrome