0

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

Art
  • 23,747
  • 29
  • 89
  • 101
  • possible duplicate of ['Global' object in node.js](http://stackoverflow.com/questions/4133114/global-object-in-node-js) – Tor Valamo Nov 09 '10 at 13:37

1 Answers1

1

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.

Marco
  • 1,471
  • 11
  • 17