Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
1

#include

Explorer ,
Oct 16, 2023 Oct 16, 2023

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

 

 

 

TOPICS
Scripting

Views

311
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Oct 16, 2023 Oct 16, 2023

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. 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2023 Oct 17, 2023

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

 

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 16, 2023 Oct 16, 2023

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 .

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 16, 2023 Oct 16, 2023

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2023 Oct 17, 2023

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 😞

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2023 Oct 17, 2023

Copy link to clipboard

Copied

LATEST

Ofcourse, Its possible to define global var in main.jsx and read it in lib, but I want to avoid it

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines