Create a namespace in JavaScript
by Francis[ Edit ] 2014-08-30 12:55:39
Create a namespace in JavaScript
It is used for keep our common javascript function and used where ever needed...
Step 1 : Common JS
// create nested namespace functions (factorial and Gamma Function)
var EasyMath = {
fact: function(num)
{
Math.round(num);
if(num<0)
return "Undefined";
var fact=1;
for(var i=num;i>1;i--)
fact*=i;
return fact;
},
gamma: function(num)
{
Math.round(num);
if(num<1)
return "Undefined";
var gamma = EasyMath.fact(num-1);
return gamma;
}
}
Step 2 : Your Page JS
var factorial = EasyMath.fact(inputValue);
var gamma = EasyMath.gamma(inputValue);
alert(factorial +"<=!=>"+gamma);