[英]How can I find where an object member is defined in Javascript?
Of course, most of the time, I can simply search for the identifier and look at all instances thereof. 当然,在大多数情况下,我可以简单地搜索标识符并查看其所有实例。 Often, searching for " =" or " :" will find the answer the fastest.
通常,搜索“=”或“:”会找到最快的答案。
But this technique fails is situations like this: 但是这种技术失败的情况是这样的:
// untested javascript:
function AddMemberToObject(object, value, memberName) {
object[memberName] = value;
}
var myObj = {}
// 3,000 references to myObj
// ... somewhere else
var mysteryString = thisMethodCallsAnotherMethodCallsAnotherMethodEtc();
AddMemberToObject(myObj, someFunction, mysteryString);
// 3,000 more references to myObj
Let's say I haven't discovered the above code yet. 假设我还没有发现上面的代码。 As illustrated in this example, some things that make it hard to find where a member is defined include:
如此示例所示,一些使得很难找到定义成员的地方包括:
What are some techniques for finding where the member is added to the object in difficult cases like this? 在这样的困难情况下,有哪些技术可以找到将成员添加到对象的位置? Is there a way to do this at runtime (eg make all additions to an object fire an event, which we can listen for and break on in the debugger)?
有没有办法在运行时执行此操作(例如,使对象的所有添加都触发一个事件,我们可以在调试器中监听和中断)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.