baniol
3/31/2014 - 7:01 AM

javascript, design patterns, module pattern

javascript, design patterns, module pattern

// A Module Pattern

PACKAGE_NAME.M = (function () { 
	var privatePropertyOrMethod1 = …; 

	// …

	var M = {};
		M.publicProperty1 = …;
		M.publicMethod1 = function (…) {…};
	
	// … 

	return M;
}());

// Already familiar to JavaScript professionals
// (We just prefer avoiding object literals)