[JS][CS5] question, and comments
HI All.
I must first start off by recommending anyone seriously wanting to get into Scripting, or (like me) am fairly knowledgable, but needed the resource, to check out "InDesign CS5 Automation Using XML & Javascript" by Grant Gamble. (Amazon, Kindle etc...)
I am sure I am not the only one who has made his way, stumbling and even hacking through code to produce scripts that work well, but not really understanding why certain things were done in a certain way. This books helps a great deal with this, laying a good basis for further development.
Anyway, on to my question. In the afore mentioned book, he talks about making a global variable/object that is used to pass variables into throughout the script ie:
var g = {};
main();
g = null;
function main(){
//code here
//g.win = new Window("dialog",undefined,"New Window");
//etc.....
}
I can see how this works, with "g" being a master item, but why would this be needed? It seems more confusing to me, but maybe cause I am self taught, and not really been shown the "proper" way to use variables!
Can someone explain the reason behind this for me.
Many Thanks
Roy