Splitting code into files, scopes, etc.
I keep experiencing weird, apparently-inconsistent behavior. It seems there's something fundamental I don't understand about scripting for InDesign using JavaScript.
A few questions, please:
1. When you #include one .jsx file in another, what does that mean, exactly? Is it equivalent to copying the content (the code) of one file and pasting it in another? If not, what then?
2. Is there a concept of namespace? If yes, how do you use them? If not, how do you avoid name clashing?
3. I want one script to construct an object and another script to use it. What are the possible ways to do so? What's the recommended way?
4. Sometimes when I declare a variable and assign it a value (e.g. "var x = 1;") outside any block (and in particular outside any function) and then use it in a function, even in the same file, it's undefined. Other times it's defined and has the assigned value. What decides if it's defined or not?
5. Considering a single file, does it matter, in any way, where in that file and in which order functions are declared and defined? What about more than one file?
6. Is there any mechanism of caching when it comes to running scripts? If so, is there a way to clear all caching?
7. If a script doesn't declare any target engine, is there any mechanism of persistence?
8. Is there some standard logging mechanism? What's the best way for a script to keep a log?
Thanks!
