Globals in MAX javascript - best practice
I read from the documentation that it recommends using e.g:
g = new Global("j1");
g.testvar= "value";
However if I put a value at the top in a .js file without the var keyword then the variable is accessible from other js scripts in the same patcher. Is this not a recommended approach?
e.g
//Beginning of some .js file..
tesvar = "globalvalue";
Hi !
yes and nope .its accessible within EVERY patcher . not only inside current patcher . its not recommended at all in javascript . also these variables are very slow .
using Global you can share data within your patcher across other JS instances .
Use of global variables in JavaScript is probably the Number 1 cause of impossible-to-track-down errors. Seriously.
So of course every JavaScript beginner in the world uses globals, thinking "oh, this is so nice and easy and convenient." And the problem is that the little tiny bit of code works OK on its own. But mix that into a just slightly larger project and out of the blue things stop working and you will lose hours trying to track that little sod of a problem down. Make that a larger project with multiple programmers and you will waste days of company time looking for the bugger.
Ok - thanks for the input!