-
Notifications
You must be signed in to change notification settings - Fork 0
3.02 JS Module Pattern
Ernesto Valdes edited this page Jun 9, 2015
·
4 revisions
Modules are an integral piece of any robust application's architecture and typically help in keeping the units of code for a project both cleanly separated and organized.
var myNamespace = (function () {
//
var myPrivateVar, myPrivateMethod;
// A private variable
myPrivateVar = 0;
// A private function
myPrivateMethod = function( foo ) {
console.log( foo );
};
return {
// A public variable
myPublicVar: "foo",
// A public function utilizing privates
myPublicFunction: function( bar ) {
// Work with private variable
myPrivateVar++;
// Call private method
myPrivateMethod( bar );
}
};
})();