Check this JavaScript Module Pattern
and this Learning JavaScript Design Patterns
Module example:
var MyModule = (function($){
var MY_CONSTANT = 123;
var _myPrivateVariable = 'TEST MEH';
var _$myPrivateJqueryObject = $('div.content');
var _myPrivateMethod = function(){
alert('I am private!');
};
var myPublicMethod = function(){
console.log('Public much?');
}
return {
myPublicMethod : myPublicMethod
};
})(jQuery);
MyModule.myPublicMethod();
Class example:
function Person(name, age){
this.name = name || '';
this.age = age || -1;
}
Person.prototype.greet= function(){
console.log('Hi! My name is' + this.name + '. Old ' + this.age + ' I am.');
}
var person = new Person("John", 12);
person.greet();