简体   繁体   English

全局变量未在堆栈中传递-IE8

[英]Global variable not passed down in stack - IE8

I am working on a legacy application that is breaking in Internet Explorer. 我正在研究Internet Explorer中损坏的旧版应用程序。 It has the following code: 它具有以下代码:

Script 1: /* Call script 2 */; xa(b) 脚本1: /* Call script 2 */; xa(b) /* Call script 2 */; xa(b)

Script 2: eval(script3) 脚本2: eval(script3)

Script 3: var x = x || {}; xa = function(){ ... } 脚本3: var x = x || {}; xa = function(){ ... } var x = x || {}; xa = function(){ ... }

In Firefox, this works as expected. 在Firefox中,这可以按预期工作。

In internet explorer, however, it fails by saying "x is undefined" (this is massively simplified). 但是,在Internet Explorer中,它失败并说“ x未定义”(这已大大简化了)。 I traced it back to this point in the code and noted that x is defined in script 3 but then going back down in the stack to script 2 it loses its availability/scope (I tested this by putting console.log statements in both - IE was ok with the one in script 3 but crashed for the one in script 2). 我将其追溯到代码中的这一点,并注意到x是在脚本3中定义的,但随后又在堆栈中向下返回到脚本2,它失去了可用性/作用域(我通过将console.log语句放在两者中进行了测试-IE可以使用脚本3中的一个,但因为脚本2中的一个而崩溃。

What about internet explorer and/or the eval() function causes this to happen and what are my options for fixing it? Internet Explorer和/或eval()函数会导致这种情况发生,我有哪些解决方案?

Why not set up a test and see for yourself? 为什么不设置测试并亲自查看呢?

Here is one: http://jsfiddle.net/Y3bf5/ 这是一个: http : //jsfiddle.net/Y3bf5/

It seems to work fine in IE7+. 在IE7 +中似乎工作正常。

You might want to change Script 3 to var x; x = x || {}; xa = function(){ ... } 您可能需要将脚本3更改为var x; x = x || {}; xa = function(){ ... } var x; x = x || {}; xa = function(){ ... }
This might've caused due to preemptive usage of the variable before it's been declared in this case variable x . 这可能是由于在这种情况下声明变量x之前抢先使用了变量引起的。
The fact that variable x is unavailable in Script 2 is because the eval() method failed abruptly with " x is undefined " 变量2脚本2中不可用的事实是因为eval()方法突然失败,并显示“ x is undefined
Actually I understood only a lil' bit from the piece of code that refers Script 3 实际上,我仅从引用脚本3的一段代码中了解一点点
If I could get a glimpse of it, then I might be of better help to you than now. 如果我能一窥它,那么对您来说,我可能会比现在更好。
Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM