In Node.js the global object is called `global`, but you rarely need to interact with it, and in most cases you shouldn't. If you need something that is modularized make your own module, and include it with the `require` function. And on initialization of that module you may send it your from the main library.
module.js module.exports = function (app) { theFunkyThing = {}; // now i have access to the app. return theFunkyThing; }; app.js: var app = {}; var module = require('module.js')(app); 2011/3/20 tim perkis <t...@perkis.com>: > I'm misunderstanding something about global scope in javascript, and node.js > in particular. > > I have a global data structure which drives my entire (small) node.js app. > For debugging, I wanted to be able to send a message to the app that > triggers dumping this struct to the console. > > code is like: > > var gRT = {}; > > ... do things that fill this structure > > I'm using a library defining a specialized UDP server, that accepts adding > message handling callbacks, and I add one like: > > OSCserver.addMsgHandler(/\/rt$/, function (decoded) { > console.log("gRT = " + gRT.inspect); > return true; > }); > > after the callback is invoked (manually, well after initialization code is > finished running) the console reads: > gRT = undefined > > In node there is no 'window' object that is the owner of my global, as I > understand, so, as expected window.gRT.inspect doesn't work; neither does > GLOBAL.gRT.inspect. > > Is there something I'm not understanding about global scope? -- Poetro -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com