javascript
JavaScript 里 window, document, screen, body 这几个名词的区别
在下面這個 StackOverflow 的線索里進行了討論:
https://stackoverflow.com/questions/9895202/what-is-the-difference-between-window-screen-and-document-in-javascript
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的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的JavaScript 里 window, document, screen, body 这几个名词的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kprobe分析内核kworker占用C
- 下一篇: 如何使用原生的 JavaScript 代