提问人:chiliNUT 提问时间:8/30/2014 最后编辑:Sebastian ZartnerchiliNUT 更新时间:8/31/2014 访问量:215
为什么 Firebug 没有为未定义的属性显示“未捕获的类型错误”?
Why does Firebug not show an 'Uncaught Type Error' for undefined properties?
问:
我通常使用 Firebug 进行开发,但最近我的一些脚本一直默默地失败。经过几个小时的跟踪错误,我发现我正在尝试获取未定义变量的属性。控制台没有错误,页面只是“坏了”。但是,在 Chrome DevTools 中,它可以正确识别错误。下面是一个简单的测试用例:
var x = {
i: {a:1,b:2}
}
在 Chrome 中,您可以获得
console.log(x.i.a); //1
console.log(x.iii.a); //Uncaught TypeError:
//Cannot read property 'a' of undefined
console.log('finished'); //does not execute
在 Firebug 中,您可以获得
console.log(x.i.a); //1
console.log(x.iii.a); //(nothing)
console.log('finished'); //does not execute
看这个小提琴。
因此,在真正的脚本中,当这种情况发生时,我很难追踪我的脚本停止的位置,并且我必须添加大量的控制台日志记录才能缩小错误范围。
这是一个错误,还是以某种方式是 Firebug 的预期行为,或者也许我可以调整一个设置?我正在使用 2.0.3。
答:
评论