Use the Eval method to assign the method represented by the method name as an object to the Func attribute of Method1, and the friends who need it can refer to the
The code 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 using the Eval method, the method represented by the method name we pass in is assigned to the Method1 Func property as an object. If the MethodName object is not found, the Eval method throws an exception This.func = eval (methodname); }catch (e) {alert (methodname+) does not exist! "); } var c = new M (methodname); C.func (); /** * METHOD2, relatively concise * * * 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! "); }