Javascript OOPS function

by Alaksandar Jesus Gene

HTML

<div id="register">I will get the value of firstname and last from mySite.user.register in 5 seconds.</div>

Here,
<p><b>user</b> ==> "Namespace"</p>
<p><b>action</b> ==> "Class"</p>
<p><b>registrationCredentials</b> ==> "Object"</p>
<p><b>firstname and lastname</b> ==> "Property"</p>
<p><b>this.register</b> ==> "method"</p>

JavaScript

var registrationCredentials = {"firstname":"Alpha","lastname":"Beta"};
var user = user || {}; //Initializing the namespace.


user.action = function(element){
    
   // This is a constructor and will run by default. 
    (function(){
        setTimeout(function(){
          document.getElementById(element).innerHTML = "Processing....";
        },2000)
    }())
    // This is a constructor and will run by default. 
    //This is a private function. Accessed only within user.action.
       var getname = function(name){ 
            
            return name.firstname+" "+name.lastname        
    };
    //This is a private function. Accessed only within user.action.
    
    //This block will have necessary codes to register the user.
    this.register = function(credentials){
        return getname(credentials);
    };
    //This block will have necessary codes to register the user.
};


/*Example of Closure. This function is initiated automatically*/
(function(){  
    User =new user.action("register");
   setTimeout(function(){    
document.getElementById("register").innerHTML=User.register(registrationCredentials);
}, 5000);
 }());