简体   繁体   English

javascript中具有未初始化的成员变量的未定义行为

[英]undefined behaviour with an un initialised member variable in javascript

It's 20:30 and I'm after a 6 hour bug hunt of an irritating bug caused by an uninitialized member variable. 现在是20:30,我经过了6个小时的错误搜寻,发现了一个由未初始化的成员变量引起的令人讨厌的错误。

In the our previous version we had the next few lines of code: 在我们以前的版本中,我们有以下几行代码:

var aList = new Array;
for (var iDx=0; iDx < nNumOfElements; iDx++)
{
    // Some code
    aList.nCount = someValue;   //This line
}

aList.sort(function(a, b) { return b.nCount - a.nCount ; });

In the last release someone accidentally removed the line with comment. 在最新版本中,有人不小心删除了带有注释的行。 and there was no other initialization of the member variable nCount. 并且没有其他成员变量nCount的初始化。

Some of our clients got a "Number expected" exception which is pretty obvious (in retrospect), strangely the error doesn't reproduce with our QA nor 80% of our clients! 我们的一些客户收到了“预期的数量”异常,这很明显(回想起来),奇怪的是,我们的质量检查人员或80%的客户都不会重现该错误!

How can it be? 怎么可能? is there any strict mode that we can run with that will find such pesky bugs? 我们可以使用任何严格的模式来查找此类讨厌的错误吗? what is the difference between the clients that got the exception and ones that didn't (it's not browser version nor windows version) 有异常的客户端与没有异常的客户端有什么区别(不是浏览器版本也不是Windows版本)

(our system runs only on IE6+ in a special container which makes it hard for us to write the code in normal IDE's we pretty much write it all in notepad ++) (我们的系统仅在特殊容器中的IE6 +上运行,这使我们很难在普通IDE中编写代码,而我们几乎都将其全部编写在记事本++中)

You wrote int instead of var . 您写的是int而不是var I do that all the time... 我一直都在做...

int iDx=0 should be var iDx=0 . int iDx=0应该是var iDx=0

By the way, what editor are you using? 顺便问一下,您使用的是什么编辑器? int is a "future reserved word" in ES, so a good editor may highlight it in an ugly way (gedit makes it red with a red underline by default) to bring your attention to it. int在ES中是“未来保留字”,因此好的编辑者可能会以丑陋的方式突出显示它(gedit将其默认显示为红色,并带有红色下划线),以引起您的注意。

Looks like it's a bug with IE6 related to array sorting. 看起来这是IE6中与数组排序有关的错误。

Try some of the workarounds suggested here ... 尝试这里建议的一些解决方法...

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

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