为什么 W3C Recommendation 总是说 "Document's Window object" 或 "Document object's Window object"?

Why W3C Recommendation always say "Document's Window object" or "Document object's Window object"?

W3C Web Storage (Second Edition) 文档中,建议总是说 "Document's Window object" 或 "Document object's Window object" 而不是 "Window object's Document object"。

但众所周知,我们在 javascript 中使用 window.document。

推荐中的"Document"和我们一直在javascript中使用的window.document对象有什么区别?为什么不 "Window object's Document object"?

这是因为(会话)存储与文档关联,而不是 window。或者更具体地说,它根据当前文档的来源进行初始化:

https://www.w3.org/TR/webstorage/#the-sessionstorage-attribute

When a new Document is created in a browsing context which has a top-level browsing context, the user agent must check to see if that top-level browsing context has a session storage area for that document's origin. If it does, then that is the Document's assigned session storage area. If it does not, a new storage area for that document's origin must be created, and then that is the Document's assigned session storage area. A Document's assigned storage area does not change during the lifetime of a Document.

当然,每个 window 都有它的文档,每个文档都有它的 window1 只是隐含的,在 WebStorage 规范中没有说明,也没有访问明确的关系。

所以当他们说“文档的 Window 对象”时,他们指的是 document's browsing context, accessible as document.defaultView, which are defined in the HTML spec (right next to window.document)。

1:这甚至不完全正确,他们 可能 关联了 documents/windows,但在我们访问存储的所有情况下,他们将要。