在下面這個 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的原創文章,盡在:"汪子熙":