<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);
}());
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.