在JavaScript中,如果我在变量中有一个字符串,有没有办法获得对具有该匹配名称的函数对象的引用?请注意,jQuery可供我使用,因此我也可以使用它的任何辅助方法.
例如:
myFunction = function(){};
var func_name = "myFunction";
var myFunctionPtr = ??? //how to get the function from the name
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在寻找一种方法来获取函数传递参数的名称
console.clear();
class A{
test(){
}
testCall(fnc:Function){
console.log(fnc.name); // i want it display test here not empty
console.log(fnc);
}
}
var a=new A();
a.testCall(a.test);
Run Code Online (Sandbox Code Playgroud)
你可以在jsbin http://jsbin.com/loluhu/edit?js,console中查看