[英]Get name of function created using Function constructor
I have created a function dynamically via Function constructor. 我已经通过Function构造函数动态创建了一个函数。 Now I want to get the name of the function within itself.
现在,我想在内部获取函数的名称。 How can this be possible?
这怎么可能?
var myFunc = new Function("arg", "// want the name here")
I can call the function using myFunc(arg)
but the name does not gets printed using arguments.callee.name
我可以使用
myFunc(arg)
调用该函数,但不会使用arguments.callee.name
打印名称
Update: Is there any way to get the reference atleast ie something like 更新:有没有办法获得参考至少,例如
myFunc instanceof <something>...
Functions created using the Function
constructor are anonymous, that's why .name
is empty. 使用
Function
构造函数创建的Function
是匿名的,这就是.name
为空的原因。 If for some reasons you need a named function, have a look at Is there any non-eval way to create a function with a runtime-determined name? 如果出于某些原因需要命名函数,请查看是否有任何非评估方法来创建具有运行时确定名称的函数? .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.