How to determine where an element of an object is defined in Javascript?

Of course, most of the time I can just find the identifier and look at all its instances. Often a search for "=" or ":" will find the answer the fastest.

But this method does not work, for example:

// 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

Say I have not found the code above yet. As shown in this example, some things that make it difficult to find where a member is defined include:

  • object to add a member to multiple references
  • the name of the item being added specified away from the member is added to the object. Worse however, it can be dynamically generated, even generated on the server, in which case the member name will not appear in the js source.

, ? (, , )?

+5
1

Firefox function watch(), , , .

+2

All Articles