-
-
Save tbranyen/944886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// export the API, but also create a global called "foo" | |
foo = module.exports = function (s) { | |
console.log('foo1 (global): ' + s); | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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