JSは、変数の保存方法名に基づいて方法例を実行します。


 
function a(){
alert("fun a()");
}
function b(){
alert("fun b()");
}
var methodName = "";
//method1
methodName = "a";
function method1(methodName){
// this.func ,
this.func = function(){};
try{
// eval , method1 func 。
// methodName , eval
this.func = eval(methodName);
}catch(e){
alert(methodName+"() !");
}
}
var c = new m(methodName);
c.func();

/**
* method2,
*/
methodName = "b";
function method2(methodName){
this.func = new Function(methodName+"();");
}
var c = new m(methodName);
try{
c.func();
}catch(e){
Ext.Msg.alert(methodName+"() !");
}