Skip to content

Instantly share code, notes, and snippets.

@Sljubura
Created February 15, 2013 15:15
Show Gist options
  • Save Sljubura/4960973 to your computer and use it in GitHub Desktop.
Save Sljubura/4960973 to your computer and use it in GitHub Desktop.
Name-spacing
// 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: 'smith@gmail.com'};
data.account = {};
// Solution
var CREDENTIALS = CREDENTIALS || {};
CREDENTIALS.add = function () {};
CREDENTIALS.subtract = function () {};
CREDENTIALS.data = {};
CREDENTIALS.person = {name: 'John', email: 'smith@gmail.com'};
CREDENTIALS.account = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment