获取匿名函数名称 [英] Get anonymous function name
本文介绍了获取匿名函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从本例中的函数中获取变量名称:
How to get the the variable name from within a function in this example:
// it should return A
var A = function(){ console.log(this.name); }
有没有这样的事情?
Is there something like this?
推荐答案
该功能是匿名的;它没有名字。然而,你可以给它一个名字:
That function is anonymous; it has no name. You could, however, give it a name:
var A = function a(){};
Then its name is accessible via Function.name
:
var A = function a() {};
A.name
> 'a'
这篇关于获取匿名函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文