简体   繁体   English

在哪里报告Javascript错误?

[英]Where to report Javascript bugs?

Imagine this: You want to make some things with a XML element you receive in a method. 想象一下:您想使用在方法中收到的XML元素来做一些事情。 So you try this: 所以你试试这个:

function makeNiceThings(XMLDOM){
    if(XMLDOM.getElementsByTagName("err")){
        makeReallyNiceThings(XMLDOM.getElementsByTagName("err")[0].childNodes[0].nodeValue);
    }
}

So, Javascript tells you you're trying to call childNodes[0] from a null reference. 因此,JavaScript告诉您您正在尝试从空引用中调用childNodes[0] But if you try: 但是,如果您尝试:

  function makeNiceThings(XMLDOM){
        if(XMLDOM.getElementsByTagName("err")[0]){
            makeReallyNiceThings(XMLDOM.getElementsByTagName("err")[0].childNodes[0].nodeValue);
        }
    }

It works flawlessly. 它完美地工作。

However, you update the page sometimes, and both are working again, no problems at all. 但是,有时您会更新页面,并且两者都可以再次使用,完全没有问题。

I have already faces so many situations like this, that I really want to know if there is a place I can show these bizarre errors in order to make javascript even better. 我已经遇到过很多这样的情况,我真的很想知道是否有一个地方可以显示这些怪异的错误,以使javascript更好。 Google returned me nothing but places to discover programmer errors. Google除了发现程序员错误的地方之外没有给我任何回报。 Ideas? 想法?

Well, I don't see an issue there. 好吧,我在那里看不到问题。 In the first example you may get and empty array which is not nothing. 在第一个示例中,您可能会得到并清空数组 ,这并非没有。 So the condition becomes true. 因此条件变为真。 Whereas in the second example you do what you really meant to do — check if there's an element with index 0. 而在第二个示例中,您将执行真正的工作—检查是否存在索引为0的元素。
Or, if you are really convinced that this is not your fault, you should do what Rocket Hazmat said: 或者,如果您真的确信这不是您的错,则应该按照Rocket Hazmat所说的做:

Bugs with JavaScript itself should be reported to the bug tracker of the browser. JavaScript本身的错误应报告给浏览器的错误跟踪器。 Though, chances are this is not a bug with JavaScript. 虽然,这可能不是JavaScript的错误。

But most probably this is a mistake in the code. 但是很可能这是代码中的错误。 If there's no err elements, you'll get an empty array and the condition will be evaluated to true ; 如果没有err元素,您将得到一个空数组 ,条件将被评估为true but there's no 0th element — that's why you get an exeption. 但是没有第0个元素-这就是为什么要获得豁免。
Hope that was clear. 希望那是清楚的。

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

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