It is possible to trace the .js files that are called when executing some JQuery event

2

For example, if a click event applied to a link call a function that is in the A.js file, which in turn needs B.js , which needs C.js . I wonder if you can know this dependency between files by browser .

    
asked by anonymous 26.09.2014 / 21:59

2 answers

2

You can enter the firebug and place a break point in the body of the function. With this you can go running line-by-line and check in depth the other functions that are called.

    
09.10.2014 / 20:07
1

Except for debugging row by row, there is no way to predict the dependencies of a given function or code snippet because they are resolved dynamically.

If there is no eval involved, you could, for example, analyze the code statically and determine what functions are called. Then you can search the entire code and see where they are.

However, please note that this method is very flawed. There are numerous situations where this simply does not work.

See, JavaScript is not a strongly typed language, so we could do that:

var obj1 = {
    f: function() { return 1 }
};
var obj2 = {
    f: function() { return 2 }
};

function generica(obj) {
  return obj.f();
}

console.log( generica(obj1) );
console.log( generica(obj2) );
console.log( generica({ f: function() {return '?'} }) );

In the example, I created two objects obj1 and obj2 , each with the f() function. Then I declare a generica() function that receives any object and executes the f() function.

In the third call to generica() , I create an anonymous object with another function f() .

The output on the console will be:

  

1

     

2

     

?

Note that you can not know which function f() it refers to, even though it may not be any of the first two. We can only know when generica() is running.

Furthermore, in JavaScript it is also possible to load and create code dynamically, so there is code that is simply not in any file.

In theory, the browser could scan all code loaded in memory in a context-determining, with the page loaded, in order to identify the possibilities. However, the usefulness of this would be dubious.

I think this kind of difficulty means that there are not many solutions (if any) for this tracking problem.

Welcome to the world of dynamic languages. ;)

    
09.10.2014 / 20:41