I'm running into difficulty with understanding the scope of a variable that I thought would be global.
Rather than figuring it all out, I thought maybe it would be better to declare my own global namespace and keep my stuff in there.
Is this the way to do it?
client/main.js
MyNamespace = {};
client/some_other_file.js
MyNamespace.greeting = 'hello world';
Yes, that's the recommended way to do it. Using a namespace like your example gives you two things:
The only thing you need to be careful of is load order. It may make more sense to put the declaration under
lib
or in a package.Side note - this is essentially the same thing a package export gives you.