[英]The best way to track method invocation in Javascript
I am a beginner in JavaScript, and I am now given a project that used Javascript heavily. 我是JavaScript的初学者,现在得到了一个大量使用Javascript的项目。 In most of the JS files, it will contain statements of the following format:
在大多数JS文件中,它将包含以下格式的语句:
Jebber.Ajax.enqueueAction(smsType, true, options, callback);
I am familiar with Java, so I assume there might be some import or sth. 我对Java很熟悉,因此我认为可能有些导入或其他内容。 at the top of the file, but there isn't any, and there is no explicit definition of "Jebber" variable.
在文件的顶部,但没有任何内容,也没有“ Jebber”变量的明确定义。 So I am curious about where does this Jebber variable come from.
所以我很好奇这个Jebber变量来自哪里。 I am using Eclipse to edit the JavaScript files, it seems F3 doesn't work to retrieve the definition of a method.
我正在使用Eclipse编辑JavaScript文件,似乎F3无法检索方法的定义。
So I am a little bit stuck here:could experts teach me a good way to dive through a large collection of JavaScript files to find the definition of variables/functions etc.? 因此,我有些困惑:专家们可以教我一个很好的方法来浏览大量JavaScript文件来查找变量/函数等的定义吗? Thanks in advance.
提前致谢。
You can do that using JS Object setters : 您可以使用JS Object setters来做到这一点:
Object.defineProperty(window, 'Jebber', {
set: function() {
debugger;
},
get: function() {}
});
When something is assigned to a global Jebber
variable you'll get a break in a js debugger (use the one in chrome dev tools for example) 将某些内容分配给全局
Jebber
变量后,您将在js调试器中中断(例如,使用chrome开发工具中的一个)
Live demo: http://jsfiddle.net/XtZkJ/ 现场演示: http : //jsfiddle.net/XtZkJ/
Open debugger and see on the stack trace - it will point to the exact line the variable modified. 打开调试器并查看堆栈跟踪-它会指向变量已修改的确切行。
“导入”将是HTML文件而不是脚本文件中的<script>
标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.