我无法理解为什么 window
在 self
下,而 self
在 window
对象下。
如果您转到开发工具或 Firebug 并编写 window
,您将得到 DOM window
对象,self
位于该对象下。奇怪的是 window
又在 self
下了!
你可以写
window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self
你仍然得到 window
对象!
怎么办?!
最佳答案
在对我的其中一条评论的回应中:
It is a circular reference, so it doesn't end. The compiler only creates one reference. It just happens to be a reference back to the original object on which the reference was created. That's why you can do window.window.window... Like this: var obj = {}; obj.obj = obj;. There's only one reference created but it's a reference back to the original, so you can do obj.obj.obj.obj.obj.obj.obj === obj.
评论可以在这里看到:Is window really global in Javascript?
关于javascript - 窗口对象中的奇怪自身对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7015635/