在Flex中,从功能对象中获取函数名函数、象中、功能、Flex

由网友(暧昧是慢性毒药ペ)分享简介:给出一个函数对象,你可以得到它的名字作为一个字符串?见例如:Given a Function object, can you get its name as a String? See example:function doThingWithCallback(callback:Function):void {tr...

给出一个函数对象,你可以得到它的名字作为一个字符串?见例如:

Given a Function object, can you get its name as a String? See example:

function doThingWithCallback(callback:Function):void {
   trace("i'm going to run " + callback); // outputs "i'm going to run function Function() { }"
}

function foo():void {
   ...
}

doThingWithCallback(foo);

这个例子是有点武断,但它是围绕函数对象传递时,得到的函数名进行调试,尤其是非常有用的。

This example is sort of arbitrary, but it would be very useful to get function names for debugging, particularly when passing around Function objects.

推荐答案

看到最好的答案this问题。

据我所知,一个函数的名称只能在功能上调用堆栈确定。

To my knowledge, the name of a function can only be determined while the function is on the callstack.

阅读全文

相关推荐

最新文章