Last active
August 29, 2015 14:07
-
-
Save soyuka/03b7476b61866a892d7b to your computer and use it in GitHub Desktop.
Opinion about global wrappers in nodejs
This file contains hidden or 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
//global variable | |
test = 'hello'; | |
//is exactly the same as | |
global.test = 'hello'; | |
//local variable - this will definitly override your global variable | |
var test = 'hello'; | |
//using the process scope, if, and really if, you can't do without a global variable | |
process.test = 'world'; | |
//Now both will be defined and using `process` will avoid any confusion | |
console.log(test + process.test); | |
//hello world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, some modules are defining global variables and could be a headache when you define a variable and everything breaks.
For example, the famous colors package is extending
String
.Global variables could become handy to store configuration objects so that you won't have to require it on each page.
The worst I've seen is the shelljs module.
If you use the global version you'll require this file.
Assuming you did:
Why the heck?
The
global.js
file will export each key of themain
file and L131 states:... BOOM 😑