Wednesday, December 9, 2009

Namespace approach to call a javascript method

html snippet:

javascript snippet: index.js
myApp = new Object();

myApp.fun=function(method1){
alert('inside overidden method');
if(arguments.length == 1)
window[method1]();
else if(arguments.length == 2)
window[method1](arguments[1]);
else if(arguments.length == 3)
window[method1](arguments[1], arguments[2]);
else if(arguments.length == 4)
window[method1](arguments[1], arguments[2], arguments[3]);
else if(arguments.length == 5)
window[method1](arguments[1], arguments[2], arguments[3], arguments[4]);
};
function invokerMethod(method){
if(typeof myApp != "undefined"){
myApp.fun(method);
}
else{
alert('namespace is not created for this release');
fun(method);
}
}

Actual method: test.js
function one(){
alert('actual method....');
}