【发布时间】:2012-05-03 08:06:58
【问题描述】:
我对导致 IE8 中的无限循环的以下循环感到困惑
for (var i in theArray) {
this.theArray.push(theArray[i]);
}
IE8 陷入无限循环,我不明白为什么,因为 this.theArray 是一个全局数组,而 theArray 是一个局部变量。
如果我有类似以下的情况,我会理解会发生无限循环:
for (var i in theArray) {
theArray.push(theArray[i]);
}
这只发生在 IE8 中。 IE8 对变量和作用域的处理方式不同吗?
编辑
这是我在一个对象中的内容
this.theArray = new Array();
this.selection = function(theArray) {
for (var i in theArray) {
this.theArray.push(theArray[i]);
}
}
编辑
我发现我将全局变量作为参数传递给函数。呸!为什么这在 IE8 中不起作用?
【问题讨论】:
-
这段代码在哪里运行?在全球范围内?
-
为什么不改本地var的名字??????
-
我们能看到整个代码吗?或者至少是我们可以测试的精简版本。另外,其他浏览器的控制台说什么?当循环无限时,其他浏览器有一个内部“断路器”。
-
我已经添加了我正在使用的代码。
标签: javascript