Get name as String from a Javascript function reference?

前端 未结 8 2005
Happy的楠姐
Happy的楠姐 2020-12-25 11:27

I want to do the opposite of Get JavaScript function-object from its name as a string?

That is, given:

function foo()
{}

function bar(callback)
{
           


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 12:10

    var name = callback.name;
    

    MDN:

    The name property returns the name of a function, or an empty string for anonymous functions:

    Live DEMO

提交回复
热议问题