调试引发alert()的JS代码 [英] debug JS code which triggers an alert()

查看:207
本文介绍了调试引发alert()的JS代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ext-js库构建的系统。系统的一部分列出了通过在线商店流动的订单。单击一行时,会显示其他订单明细。几天之后,一旦单击一行,就会显示一条消息FIXME:created panelID ...。之后,正常的功能继续,即错误消息只是令人烦恼,并且在出现后不会中断正常执行。



我正在尝试调试JS代码以查看在什么情况下出现错误信息,即为什么突然出现。我试图用FireBug这样做。有没有人可以使用任何提示来实现我的目标,即建立什么代码行触发alert()?
任何关于此事的输入都非常感谢。

解决方案

Firebug具有以编程方式创建断点的命令行API。例如:

  debug(fn); 

为函数 fn 创建一个断点。不幸的是,这不能用于具有本地代码的功能(内置函数,如 alert )。但是,您可以使用这个技巧。



使用此脚本在代码中插入脚本块 -

  window.alert_ = window.alert; 
window.alert = function(){
alert_.apply(window,arguments)
};

你所做的是用你自己的window.alert来重新定义一样的事情。 / p>

现在在firebug中附加断点:

  debug(alert) ; 

下一次脚本调用alert时,您将在函数中获取断点。然后,您可以分析堆栈跟踪并找出从哪里调用。


I have a system which is built using the ext-js library. Part of the system lists orders that are flowing through an online store. When a row is clicked, additional order details are shown. A few days back, a message saying "FIXME: created panelID..." began to appear as soon as a row is clicked. After that, normal functioning continues, i.e. the error message is just annoying and doesn't break normal execution after it appears.

I am trying to debug the JS code to see under what circumstances does the error message appear, i.e. why did it suddenly start appearing. I am trying to do this with FireBug. Does anyone have any tips I could use to achieve my goal of establishing what line of code triggers the alert()? Any input on the matter is much appreciated.

解决方案

Firebug has a command line API to programmatically create breakpoints. For example:

debug(fn);

creates a breakpoint to the function fn. Unfortunately this can't be used for functions with native code (built-in functions like alert). However, you can use this trick.

Insert a script block in your code with this script-

window.alert_ = window.alert;
window.alert = function() {
    alert_.apply(window,arguments)
};

What you've done is to redefine window.alert with your own which does the same thing.

Now attach the breakpoint in firebug with:

debug(alert);

Now the next time a script calls alert, you will get a breakpoint in your function. You can then analyze the stack trace and find out where it is getting called from.

这篇关于调试引发alert()的JS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆