Created
September 30, 2014 12:22
-
-
Save ethyde/7326c81c00b33a0cdd0b to your computer and use it in GitHub Desktop.
Reduce global VAR http://jsfiddle.net/LmTXD/1/
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
| // BAD | |
| var name = 'Jeffrey'; | |
| var lastName = 'Way'; | |
| function doSomething() { | |
| // do something | |
| } | |
| console.log(name); // Jeffrey -- or window.name | |
| // BETTER | |
| var DudeNameSpace = { | |
| name : 'Jeffrey', | |
| lastName : 'Way', | |
| doSomething : function() { | |
| return "Do something"; | |
| } | |
| }; | |
| // USAGE | |
| $('#result').append('<div>' + DudeNameSpace.name + '</div>'); // Jeffrey | |
| $('#result').append('<div>' + DudeNameSpace.doSomething() + '</div>'); // Do something |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment