在窗口对象奇怪的自我对象 [英] Weird self object in window object

查看:93
本文介绍了在窗口对象奇怪的自我对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么窗口正在正在窗口对象。

如果你去DEV-工具或萤火虫和写入窗口你有 DOM窗口对象是这样的对象下。怪异的是,窗口正在又来了!

您可以写

<$p$p><$c$c>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.window.window ...喜欢这样:var OBJ = {}; obj.obj = OBJ ;.
  只有一个创建的参考,但它是一个引用回
  原来,所以你可以做obj.obj.obj.obj.obj.obj.obj === OBJ。


注释可以在这里看到:<一href=\"http://stackoverflow.com/questions/6679635/is-window-really-global-in-javascript/6680030#comment-8136449\">Is窗口在Javascript真正全球性的?

I can't understand why window is under self and self is under window object.

if you go to dev-tools or Firebug and write window you got DOM window object that self is under this object. The weird part is that window is under self again!

You can write

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

and still you get window object!

How?!

解决方案

In a response to one of my comments:

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.

Comment can be seen here: Is window really global in Javascript?

这篇关于在窗口对象奇怪的自我对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆