Skip to main content

Posts

Showing posts from June, 2013

Best Practices in Implementing OOP JavaScript (Namespaces , Classes , Objects methods in JavaScript )

<script type= "text/javascript" charset= "utf-8" > // Root Namespace var Namespace = {}; // Create a Class Namespace.Class1 = function () { }; // Pulic Methods Namespace.Class1.prototype.M1 = function () { alert( "M1" ); }; // Create a Class with variables and members Namespace.Class2 = function () { // Public Variable this .x = "Pubilic variable" ; // Private Variable var y = "private variable" ; // Call private method. Only Constructor can call it privateMethod(); // Private Method function privateMethod() { // Can access private variable //Can not access public variable y = 5; } //Privilaged method. Can access both public and private // call publically this .privatePublicMethod = function () { // access public variabl