Skip to content

Instantly share code, notes, and snippets.

@ethyde
Created September 30, 2014 12:22
Show Gist options
  • Select an option

  • Save ethyde/7326c81c00b33a0cdd0b to your computer and use it in GitHub Desktop.

Select an option

Save ethyde/7326c81c00b33a0cdd0b to your computer and use it in GitHub Desktop.
Reduce global VAR http://jsfiddle.net/LmTXD/1/
// 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