博客 / 詳情

返回

JavaScript 裏 window, document, screen, body 這幾個名詞的區別

在下面這個 StackOverflow 的線索裏進行了討論:

https://stackoverflow.com/que...

在這裏插入圖片描述

window

Window is the main JavaScript object root, aka the global object in a browser, also can be treated as the root of the document object model. You can access it as window

相當於 瀏覽器 JavaScript 編程環境裏的 root 對象,也可以看成是 document 對象模型的父節點。作為全局對象被訪問。

window.screen

window 全局對象的一個屬性,包含了物理屏幕的尺寸信息。

window.screen or just screen is a small information object about physical screen dimensions.

window.document

window.document or just document is the main object of the potentially visible (or better yet: rendered) document object model/DOM.

頁面被渲染後的可見部分對應的 DOM 對象。

body

是上文描述的 document 對象中一個名為 body 的子節點。

Since window is the global object you can reference any properties of it with just the property name - so you do not have to write down window. - it will be figured out by the runtime.

因為 window 是全局對象,因此訪問其屬性時,可以省略 window. 的寫法。

因此通過下列方式訪問 window 裏的屬性,同樣有效:

更多Jerry的原創文章,盡在:"汪子熙":

user avatar nogeek 頭像 zbooksea 頭像 nidexiaoxiongruantangna 頭像
3 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.