简体   繁体   中英

Get name of function created using Function constructor

I have created a function dynamically via Function constructor. 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

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. 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? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM