javascript 中的window, document, screen都有什么区别?

这篇博客解释了JavaScript中的全局对象window、screen和document之间的区别。window是全局对象,包含DOM的根;screen提供了有关物理屏幕尺寸的信息;document则是当前可见DOM的主体。由于window是全局对象,可以直接引用其属性而不需要明确写window前缀。
摘要由CSDN通过智能技术生成

谷歌之后,从stackoverflow上找到的高赞答案:

https://stackoverflow.com/questions/9895202/what-is-the-difference-between-window-screen-and-document-in-javascript

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

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

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

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是javascript中的全局变量。document其实是window.document,而screen其实是window.screen。由于window是全局变量,所以window被省略了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值