什么定义了 javascript 全局对象中 DOM `document` 属性的可用性?

发布于 2024-08-12 22:43:28 字数 1284 浏览 1 评论 0原文

我对 javascript 有点陌生,试图了解 W3C DOM 标准和 ECMAscript 定义的 javascript 如何互操作。

具体来说,据我了解:

ECMAscript 标准定义了全局对象的存在,它提供了诸如 parseInt(string) 之类的函数,并明确允许通过它访问其他内置对象的存在,但是这些的定义留给实现。

W3C DOM 标准定义了一组与 HTML 文档的结构相对应的对象和接口。其中之一是包含 getElementById 等方法的 Document 对象(大写 D)。然而,据我所知,该规范并未定义如何获取表示浏览器中当前文档的此类对象的实例。

基本上,我所追求的是 - 在哪里明确指出在网页中执行 javascript 时,我可以调用 document.getElementById("someId") (注意小写的 d),并且 < code>document 属性代表正在执行 JavaScript 的文档的 DOM?

这个特定的细节是特定于实现的吗?难道不应该在某个地方标准化吗?我能得到的最接近的是 Gecko DOM 文档,它似乎暗示 documentDocument 是等效的。我以为javascript区分大小写?或者我只是在解释这些事情时真的很肛门?


编辑:

在 Jason 发表评论后,我仔细浏览了 HTML 5 标准工作草案,我认为捕捉到我正在寻找的内容的是

6.5.3.3 创建脚本

...用户代理必须运行以下步骤:

<代码>4。设置脚本的全局对象、脚本的浏览上下文、脚本的 URL 字符编码和脚本的基本 URL

6.5.3.1 全局对象的状态

“这通常是一个 Window 对象。在 JavaScript 中,这对应于全局对象。”

此外,6.1 浏览上下文指出

“用户主要通过其与用户代理交互的主视图是默认视图。表示此视图的 AbstractView 对象还必须实现 Window 接口,并被称为 Document 的 Window 对象。WindowProxy 对象转发所有内容到活动文档的默认视图的 Window 对象。”

由于 AbstractView 接口按照 DOM 2 Views 规范实现文档属性,因此这可能定义了 Javascript 全局文档属性的存在。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丶视觉 2024-08-19 22:43:28

这被非正式地称为“DOM level 0”,尽管它已经稳定了十多年,但从未标准化。

窗口, < a href="http://dev.w3.org/html5/spec/Overview.html#documents" rel="nofollow noreferrer">document等将被标准化HTML 5(即将推出的 W3C 标准)。

至于区分大小写:Document 是接口的名称。这是一种类型。 document instanceof Document 为 true。

HTMLDocument 是另一个接口。 document instanceof HTMLDocument 也是如此。

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.

后知后觉 2024-08-19 22:43:28

这可能无济于事,但我对你所问问题的理解表明你在对象的实例和对象本身之间有点困惑。

当您调用 document.getElementById("someId") 时,您正在调用名为 document 的实例化对象,它是对象 Document 的实例>。这样,如果您执行 document instanceof Document 它将返回 true。

我不知道标准是否规定浏览器将创建 Document 元素的实例,或者何时创建,因为我从未阅读过该规范。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文