在 Firebug 中调试 Javascript 函数
我正在尝试使用 Firebug 调试遗留脚本。据我所知(我昨天得到的) 我们使用Step over (F10)
逐行调试,使用Step into (F11)
深入研究JS函数。 但是当我在任何 JS 函数调用上使用 Step into
时,它会将控制权转移到下一行。我想看看这个函数里面隐藏了什么。我们怎样才能做到呢?
我在函数内部保留了断点,然后尝试Step into
,然后它在函数体内进行控制。但查找各个函数方法并设置断点比较繁琐。 还有其他方法吗?或者哪个是正确的方法?
例如:
i2b2.ONT.ctrlr.FindBy = {
clickSearchName: function() {
// do some stuff
i2b2.ONT.ctrlr.FindBy.doNameSearch(search_info); // I tried Step into here
// some more stuff
}
doNameSearch: function(inSearchData) {
// If I set break-point here then only I can debug it
// or it directly takes control to `// some more stuff` in `clickSearchName:function`
}
}
PS:它还多调用外部JS函数。
谢谢,
阿金基亚。
I am trying to debug legacy scripts with Firebug. As per my knowledge (Which I got yesterday)
we use Step over (F10)
to debug line by line and Step into (F11)
to dig into JS function.
But when I use Step into
on any JS function call, it takes control to next line. I want to see what is hidden inside the function. How can we do it ?
I kept break-point inside the function and then tried Step into
then it takes control inside the function body. But it is tedious to find each function method and set break-point.
Is there any other way to do it ? or which is the right way ?
For example :
i2b2.ONT.ctrlr.FindBy = {
clickSearchName: function() {
// do some stuff
i2b2.ONT.ctrlr.FindBy.doNameSearch(search_info); // I tried Step into here
// some more stuff
}
doNameSearch: function(inSearchData) {
// If I set break-point here then only I can debug it
// or it directly takes control to `// some more stuff` in `clickSearchName:function`
}
}
PS: It also more external JS function calls.
Thanks,
Ajinkya.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果该函数有 JS 源,“Step into”将单步执行该函数。如果不是(例如
document.getElementById("foo")
),它将跳过它,因为它没有任何它可以理解的内容。如果您能给我们指出一个工作示例,其中您遇到了问题(无论是问题的 jsFiddle 减少还是工作网页),并附有相关代码位置的说明,
从您的代码示例来看,我们可能可以提供更多帮助,我想知道您想要做什么 。进入的代码行。 with
clickSearchName
定义了一个函数,因此,直到后面的代码实际调用clickSearchName
时,它才会进入该函数。打破函数的定义并尝试在函数未执行时进入该函数,但这只是一个猜测,因为我们没有可以自己尝试的工作示例。"Step into" will step into the function if there is JS source for the function. If not (like for
document.getElementById("foo")
, it will step over it since it doesn't have anything that it understand to step into.If you can point us to a working example where you are having the problem (either a jsFiddle reduction of the problem or a working web page) with instruction on where the relevant code is, we can probably help more.
Judging by your code example, I'm wondering what you're trying to step into. The line of code that starts with
clickSearchName
defines a function. It doesn't execute it. So, it won't go into that function until some later code actually callsclickSearchName
. So, perhaps you're breaking on the definition of the function and trying to step into the function when it isn't being executed. That's just a guess though since we don't have a working example to try ourselves.将行
debugger;
添加到代码中要中断调试器的位置,它是一个 JavaScript 关键字,应该可以执行您想要的操作。只要记住在调试完代码后将其取出即可。Add the line
debugger;
to your code at the place where you want to break into the debugger, it's a JavaScript keyword, which should do what you want. Just remember to take it out when you're done debugging your code.