自我与窗户有什么区别? [英] What's the difference between self and window?
问题描述
我有一个JavaScript来处理检测页面是否在框架中。我使用top.frames []等,一切正常。
I have a JavaScript that deals with with detection whether the page is in frames or not. I used top.frames[] etc. and everything works fine.
在这个脚本中,我注意到我可以互换地使用窗口或自我,一切仍然有效。在HTML页面中使用窗口是否与self相同?
In this script I noticed that I can use "window" or "self" interchangeably and everything still works. Is "window" same as "self" when used in HTML page?
推荐答案
来自 Javascript:The Definitive Guide :
Window对象定义了许多
属性和方法,允许你
来操作网页浏览器窗口。
它还定义了将
引用到其他重要对象的属性,例如
Document对象的document
属性。最后,Window
对象有两个自引用的
属性,窗口
和self
。你
可以使用全局变量到
直接引用Window对象。
The Window object defines a number of properties and methods that allow you to manipulate the web browser window. It also defines properties that refer to other important objects, such as the
document
property for the Document object. Finally, the Window object has two self-referential properties,window
andself
. You can use either global variable to refer directly to the Window object.
简而言之,两者 window
和 self
是对Window对象的引用,它是客户端javascript的全局对象。
In short, both window
and self
are references to the Window object, which is the global object of client-side javascript.
这篇关于自我与窗户有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!