joyent/node — Issue #1846: repl's `global` cannot be modified by a module
Author: gfxmonk
Created: 2011-10-09 01:59:53+00:00
State: open

I might be missing something. I realise that the repl's `global` is not actually a global (#771), but I think this should still work:

foo.js:

exports.install = function(g) {
g.myNumber = 123;
}

with no REPL:

$ node -e 'require("./foo.js").install(global); myNumber'
123

with repl:

$ node
> require("./foo.js").install(global)
> myNumber
ReferenceError: myNumber is not defined
at [object Context]:1:1

it looks to me like the REPL's `global` context cannot be passed to functions defined in other modules (or perhaps it can, but they can't add properties to it). And when you try, it silently fails rather than giving an error to that effect.