The code copy is as follows:
function a(){
alert("fun a()");
}
function b(){
alert("fun b()");
}
var methodName = "";
//method1
methodName = "a";
function method1(methodName){
//Initialize this.func property,
this.func = function(){};
try{
// Here we use the eval method to assign the method represented by the method name we passed in as an object to the func attribute of method1.
//If the corresponding object of methodName cannot be found, the eval method will throw an exception
this.func = eval(methodName);
}catch(e){
alert(methodName+"() does not exist!");
}
}
var c = new m(methodName);
c.func();
/**
* method2, relatively simple
*/
methodName = "b";
function method2(methodName){
this.func = new Function(methodName+"();");
}
var c = new m(methodName);
try{
c.func();
}catch(e){
Ext.Msg.alert(methodName+"() does not exist!");
}