[javascript-dev] Re: Re: Global variables in .js
John Pitcairn
cycling74forum at opuslocus.net
Thu Feb 21 16:27:11 MST 2008
- Previous message: [javascript-dev] Re: Global variables in .js
- Next message: [javascript-dev] Global variables in .js
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Quote: Gary Lee Nelson wrote on Fri, 22 February 2008 10:13
----------------------------------------------------
> Yes, that seems to be correct although somewhere I think the documentation says that variable can be know by ALL .js objects in the patch and not just instances of a particular file. Is this true?
I think that's referring to a global Object created with "new Global()". I remember the global var behaviour I'm referring to being somewhat obscure and undocumented except on this list. I could be wrong on that though.
> Can you declare a global variable without giving it an initial value or initialize only when the first instance is loaded?
Not with the var syntax. But using the object, something like this(?):
var myglobal = new Global('globalname'); // access/create a shared named global object, store locally as "myglobal"
if(!myglobal.myvalue && myglobal.myvalue !== 0 && myglobal.myvalue !== false) myglobal.myvalue = "inited"; // test for existence of global object's "myvalue" property, init if required, note strict type test for false and 0 is required if those might be inited values
- Previous message: [javascript-dev] Re: Global variables in .js
- Next message: [javascript-dev] Global variables in .js
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
