Is there any reason why the following code:
global.myNamespace = {};
fails to add 'myNamespace' to the global object, i.e.
typeof global.myNamespace
returns
'undefined'
Node.Js 0.3.1-pre
Is there any reason why the following code:
global.myNamespace = {};
fails to add 'myNamespace' to the global object, i.e.
typeof global.myNamespace
returns
'undefined'
Node.Js 0.3.1-pre
You're probably trying this code in the node-repl. The repl is special in that every command submitted gets a new context. That means a brand new global object. Any of your variables in the old context can still be found, but all of the global js variables are replaced with brand new ones. That includes global, Object, Array, etc.
What you're doing will work fine in a script. Just not in the repl.