Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Forked from remy/foo1.js
Created April 27, 2011 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbranyen/944886 to your computer and use it in GitHub Desktop.
Save tbranyen/944886 to your computer and use it in GitHub Desktop.
(function () {
// export the API, but also create a global called "foo"
foo = module.exports = function (s) {
console.log('foo1 (global): ' + s);
};
})();
module.exports = function (s) {
console.log('foo2: ' + s);
// note we can access the global from the server.js
foo1('from foo2.js');
};
// oh look, I can access the foo global variable
foo('foo2.js being loaded');
foo1 = require('./foo1'); // note - global from our server
var foo2 = require('./foo2');
foo1('from server.js');
foo2('from server.js');
// this global "foo" leaks from foo1
foo('from server.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment