简体   繁体   English

告诉已调用的javascript函数的顺序

[英]tell the order of javascript functions that have been called

I've been using Chrome scripts to identify the order of the Javascript functions that are running . 我一直在使用Chrome脚本来确定正在运行的Javascript函数的顺序

It's a bit overkill for what I'm doing right now as what I only really need is to have a log of the javascript functions that have been called. 对于我现在正在做的事情来说有点过头了,因为我真正需要的只是拥有一个已调用的javascript函数的日志。

What are you guys here using for that purpose? 你们在这里用什么呢?

Thanks for the feedback. 感谢您的反馈。

Sometimes I like to put console.log("function name") at the top of each function that I want to track. 有时我喜欢将console.log(“ function name”)放在要跟踪的每个函数的顶部。 That will output the string "function name" to the console, which you can see in the Chrome developer tools window. 这会将字符串“功能名称”输出到控制台,您可以在Chrome开发者工具窗口中看到该字符串。

Try this one: http://eriwen.com/javascript/stacktrace-update/ 试试这个: http : //eriwen.com/javascript/stacktrace-update/

Javascript stacktrace that works across most browsers. 适用于大多数浏览器的Javascript stacktrace。

if you want to be cool, and create overhead you can do this. 如果您想变酷并增加开销,可以这样做。

function callFn( fn ){

  console.log( arguments[0].name );
  fn.apply(this, Array.prototype.slice.call(arguments,1) );
  //Sorry about the second line, it's necessary because of
  // shortcomings of JavaScript (for now!)
}

I'm posting this because I thought it was a cool idea, but not very feasible. 我发布此消息是因为我认为这是一个很棒的主意,但不太可行。 It is common for people to add something like this where they need to debug code. 人们通常在需要调试代码的地方添加类似的内容。 Depending on your minifying engine, it will automatically remove this sort of code on compilation. 根据缩小引擎的不同,它将在编译时自动删除此类代码。

//LOG
console.log( arguments.callee.name );
//LOG

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

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