i.e. what's the equivalent of the browser's "window" object, to which top level functions are attached?
The following code succeeds in the REPL:
var assert = require('assert');
function foo() { };
assert.ok(foo == this["foo"]);
However in a script (or a module) it fails--in both cases "this" is an empty object.
I'm wondering about this so I can easily export all functions visible in a module's namespace--I want to be able to do something like:
function foo() { };
function bar() { };
["foo", "bar"].forEach(function (k) {
exports[k] = ???;
});
(eval(k) works for the ???, but, ugh.)
var foo = exports.foo = function(){...};. Or, you could create your own object containing the functions you'll later export:var fns = {}; fns.foo = function(){...}; ... fns.forEach(...);