Skip to content

Instantly share code, notes, and snippets.

@mbjordan
Created December 6, 2012 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbjordan/4226179 to your computer and use it in GitHub Desktop.
Save mbjordan/4226179 to your computer and use it in GitHub Desktop.
no-class.js

When writing a new JS lib or embeddable file, I use this structure to avoid cluttering the global namespace.

I am defining an object and placing the functions inside the object. This is nothing new or unheard of, just my way of doing it.

Notice I placed all the variables into their own sub-object, this is done to ease development.

var MyLib = {
vars: {
var1: 'value1',
var2: 'value2'
},
func1: function () {
return this.vars.var1;
},
func2: function () {
alert("This is func2");
}
};
MyLib.func1();
MyLib.func2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment