开发者

What defines the availability of the DOM `document` property in the javascript global object?

I am a bit new to javascript and was trying to understand how the W3C DOM standard and javascript as defined by ECMAscript interoperate.

Specifically, as I understand it:

the ECMAscript standard defines the existence of a Global Object, which provides functions such as parseInt(string) and explicitly allows the presence o开发者_如何转开发f other built-in objects accessible through it, but the definition of these is left to the implementation.

The W3C DOM standard defines a set of objects and interfaces which correspond to the structure of an HTML document. One of these is the Document object (uppercase D) containing methods such as getElementById. However this specification, as far as I understand it, does not define how an instance of such an object representing the current document in a browser may be obtained.

Basically, what I am after is - where is it explicitly stated that when executing javascript in a web page, I can call document.getElementById("someId") (note lowercase d), and that the document property represents the DOM of the document in which the javascript is executing?

Is this particular detail implementation-specific. Shouldn't it be standardised somewhere? The nearest I can get is the Gecko DOM documentation which appears to imply that document and Document are equivalent. I thought javascript was case sensitive? Or am I just being really anal about interpreting these things?


Edit:

Trawling through the HTML 5 standard working draft after Jason's comment, I think the bit that captures what I'm looking for is

6.5.3.3 Creating scripts

...the user agent must run the following steps:

4. Set up the script's global object, the script's browsing context, the script's URL character encoding and the script's base URL

6.5.3.1 states of the global object that

"This is typically a Window object. In JavaScript, this corresponds to the global object."

Further, 6.1 Browsing Contexts states

"The main view through which a user primarily interacts with a user agent is the default view. The AbstractView object that represents this view must also implement the Window interface, and is referred to as the Document's Window object. WindowProxy objects forward everything to the active document's default view's Window object."

Since the AbstractView interface implements the document property as per DOM 2 Views spec, this presumably is what defines the existence of the Javascript global document property.


This is informally called "DOM level 0" and it has never been standardized, despite being stable for a decade and more.

window, document, and so on will be standardized in HTML 5 (a forthcoming W3C standard).

As for case-sensitivity: Document is the name of an interface. It's a type. document instanceof Document is true.

HTMLDocument is another interface. document instanceof HTMLDocument is true, too.


This may not help but my understanding of what you are asking says you are getting a little confused between and instance of and object and the Object itself.

When you call document.getElementById("someId") you are making a call to the instantiated object named document which is an instance of the object Document. This is such that if you execute document instanceof Document it will return true.

I don't know if the standard states that a browser will create an instance of the Document element or when it does though as I have never read the spec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜