简体   繁体   English

跟踪Java中方法调用的最佳方法

[英]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.

相关问题 JavaScript:作为函数/方法调用 - JavaScript: invocation as a function/method 通过javascript跟踪表单中的更改的最佳方法是什么? - What is the best way to track changes in a form via javascript? 进行原型制作时跟踪javascript对象引用的最佳方法是什么 - What the best way to keep track of a javascript object reference when prototyping 用JavaScript调用Rails红宝石方法 - rails ruby method invocation by Javascript 在JavaScript中检查方法可用性的最佳方法 - Best way of checking method availability in JavaScript 方法调用模式中的Javascript“this”指针未指向对象 - Javascript “this” pointer in Method Invocation Pattern not pointing to object 等待调用/方法返回 javascript signalr 中的值 - Wait for invocation/method to return a value in javascript signalr JavaScript方法中的“未捕获的TypeError:非法调用” - “Uncaught TypeError: Illegal Invocation” in a javascript method Javascript方法调用模式示例不起作用,为什么? - Javascript The Method Invocation Pattern Sample is not working, why? 跟踪多个文本输入的值以确认它们在 JavaScript/React 文字游戏中都是正确的最佳方法 - Best way to track values of multiple text inputs to confirm they are all correct in a JavaScript/React word game
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM