Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

javascript - Javascript中的窗口,屏幕和文档有什么区别?(What is the difference between window, screen, and document in Javascript?)

I see these terms used interchangeably as the global environment for the DOM.

(我认为这些术语可以互换使用,作为DOM的全局环境。)

What is the difference (if there is one) and when should I use each one?

(有什么区别(如果有的话)我应该在什么时候使用?)

  ask by TimeEmit translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

(Window是主要的JavaScript对象根,也就是浏览器中的global object ,也可以视为文档对象模型的根。)

You can access it as window

(您可以将其作为window访问)

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

(window.screen或just screen是一个关于物理屏幕尺寸的小信息对象。)

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

(window.document或just document是可见(或更好的:渲染)文档对象模型/ 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.

(由于window是全局对象,因此您可以仅使用属性名称来引用它的任何属性 - 因此您不必记下window.)

- it will be figured out by the runtime.

( - 它将由运行时计算出来。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...