简体   繁体   English

调试javascript函数

[英]Debugging javascript functions

Is there a way in Firebug (or any other debugger) to see the functions that are being called as a page loads? 在Firebug(或任何其他调试器)中有没有办法看到在页面加载时被调用的函数?

Edit: Breakpoint is really not what I'm looking for- I'd like to see the functions being called with the arguments that are being passed as I work on the page - something similar to the console - where I can see Http AJAX Post messages - with post values and the response. 编辑:断点真的不是我想要的 - 我希望看到函数被调用的函数在我在页面上工作时被传递 - 类似于控制台 - 在那里我可以看到Http AJAX Post消息 - 包含帖子值和响应。

Edit2: It looks like Profiler is something that I was looking for - but is there a way of looking at the parameters passed to the function and the return value? Edit2:看起来Profiler是我正在寻找的东西 - 但有没有办法查看传递给函数的参数和返回值?

You can always just print it out yourself. 你总是可以自己打印出来。 ( I know this may not be the answer you wanted.) (我知道这可能不是你想要的答案。)

But what you can do is add a 但你可以做的是添加一个

<div id="debug"></div>

in your document. 在你的文件中。

Then add: 然后加:

function log(str) {
  $('#debug').append(str); // I'm using jQuery here
}

and then you can add the logs in your javascript, eg: 然后你可以在你的javascript中添加日志,例如:

function myFunc(foo, bar, baz) {
  log("myFunc called with ("+foo+", "+bar+", "+baz+")<br/>");

  // your stuff
}

Tedious, but effective (IMO). 繁琐但有效(IMO)。

Firebug's console.log statement will dump stuff to the console for you, you just need to add console.log statements. Firebug的console.log语句会将内容转储到控制台,您只需添加console.log语句即可。 For post requests and responses, use the net panel . 对于帖子请求和回复,请使用网络面板 Personally, I think adding a debug function and div to your page is overkill. 就个人而言,我认为在页面中添加调试功能和div是过度的。

I think you need to make this more specific if you want to get more specific answers than "just use a breakpoint". 我认为如果你想获得比“仅使用断点”更具体的答案,你需要更具体。 Do you know what "code profiling" is? 你知道“代码分析”是什么吗? Is that what you want to do? 那是你想做的吗? You can google for "firebug profiler", and there is also some information right here on SO, eg Understanding Firebug profiler output 你可以谷歌搜索“firebug profiler”,这里也有一些关于SO的信息,例如了解Firebug profiler输出

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

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