Created
February 15, 2013 15:15
-
-
Save Sljubura/4960973 to your computer and use it in GitHub Desktop.
Name-spacing
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
// Clean globals with name-spacing pattern | |
// Anti-pattern | |
// Pollution with 5 objects added to global. | |
function add() {} | |
function subtract() {} | |
var container = {}; | |
var data = {}; | |
data.person = {name: 'John', email: '[email protected]'}; | |
data.account = {}; | |
// Solution | |
var CREDENTIALS = CREDENTIALS || {}; | |
CREDENTIALS.add = function () {}; | |
CREDENTIALS.subtract = function () {}; | |
CREDENTIALS.data = {}; | |
CREDENTIALS.person = {name: 'John', email: '[email protected]'}; | |
CREDENTIALS.account = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment