English 中文(简体)
IE8 陷入了fin的 lo锁,有阵列推进。
原标题:IE8 gets caught in an infinite loop with array push
  • 时间:2012-05-03 08:06:58
  •  标签:
  • javascript

我感到困惑的是,下面的路段在8号独立党中造成了无限的 lo。

for (var i in theArray) {
            this.theArray.push(theArray[i]);
}

IE8陷入了我不理解的无限圈子,为什么因为<代码>了。 “Array是一个全球阵列,而“Array<>/code>是一个地方变量。

If I had something like the following I would understand that an infinite loop would occurs:

for (var i in theArray) {
            theArray.push(theArray[i]);
}

This only happens in IE8. Does IE8 treat variables and scoping differently?

EDIT

这里,我是在物体内

this.theArray = new Array();

this.selection = function(theArray) {
    for (var i in theArray) {
        this.theArray.push(theArray[i]);
    }
}

EDIT

我发现,我把全球变数作为理由。 Duh! 为什么在第八届国际能源论坛中不这样做?

最佳回答

首先,从来不使用<>条码>。 它将通过价值和增强的特性加以振兴。

然后,this不能在你的代码中确定。 。 另外,您可能已经在地方变量中使用<代码>var,从而使<代码>“Array<>/code>指同一个全球<代码>的“Array<>/code>。

var theArray = [1,2,3];

function foo(){
    theArray = [4,5,6]; //missing var, theArray is the global theArray
    for (var i in theArray) {
        //you are pushing to the same array you are fetching from
        this.theArray.push(theArray[i]);

        //[4,5,6,4,5,6,4,5,6,.....]
    }
}
问题回答

页: 1

<代码>自为文字操作的窗口或框架,因此它喜欢查阅全球变量。

for (var i in theArray) {
    self.theArray.push(theArray[i]);
}

If that doesn t help, give the Arrays different variable names.

或:你是否确信<代码>Array是当地范围? 您在界定“Array”之前是否预先确定了var的声明?

var theArray

The way I read this, it should go into an infinite loop. You are enumerating over an array and adding items to it at the same time, ie:

阅读指数一,创建i+1,重复。

在你正在修改你所列举的藏书时,其他语言就投了炸弹,这本书将显示错误。

我感到惊讶的是,它只是在第8号国际报告中失败了。 我错过你的法典吗?





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签