#include
Copy link to clipboard
Copied
when jsx file is included in another script file, is it possible to find out by what file its included without passing parameters?
lets say I have 2 files:
lib.jsx
--
function libFunc(){
var main=???
$.writeln("I am oncluded in"+main);
};
libFunc();
~eof
main.jsx:
#include lib.jsx
~eof
Explore related tutorials & articles
Copy link to clipboard
Copied
The question is unclear to me. Are you asking how to distinguish between variables from the included file and variables from the main file? If so, the answer is: not possible. Both sets of variables are added as properties to the same global object.
Copy link to clipboard
Copied
$.fileName in lib.jsx points to ~/desktop/lib.jsx
..and I want to find out tests.jsx name somehow in lib..
create 2 files, lib.jsx and test.jsx and try runing test.jsx
lib.jx:
alert($.fileName)
~eof
test.jsx:
//@include lib.jsx
~eof
Copy link to clipboard
Copied
While this is not possible after the fact, there are multiple close possibilities.
Note that some of the global variables are introduced by cross-suite startup scripts of Adobe themselves, you would not find those.
E.g. an illustrator startup introduces subMenuBrush and several others in code that should only target Bridge.
Same with photoshop which is responsible for that tempPSVersionInfo.
For your own scripts:
You can declare the global as const rather than variable.
The redeclaration within your nested code will then fail with an error.
You would use that e.g. to track down forgotten "var" that would place them in local scope.
You can also trap write access via Object.prototype.watch().
The global object is available via $.global.
In your watch callback, you can also look at the call stack via $.stack .
Copy link to clipboard
Copied
Re-reading the original question after the first answer (sorry), this appears to be more about the top level execution rather than variable redeclarations. The mentioned $.stack and $.fileName are as close as you can get.
Copy link to clipboard
Copied
really creative ideas about const and watch, thank you! but file name in lib.jsx still point to lib.jsx location, not main.jsx 😞
Copy link to clipboard
Copied
Ofcourse, Its possible to define global var in main.jsx and read it in lib, but I want to avoid it

