apache-flex - Actionscript 3 自省(introspection)——函数名称

标签 apache-flex actionscript-3 function introspection

我正在尝试遍历对象的每个成员。对于每个成员,我检查它是否是一个函数。如果它是一个函数,我想获取它的名称并根据函数名称执行一些逻辑。我不知道这是否可能。是吗?有什么建议吗?

例子:

var mems: Object = getMemberNames(obj, true);

for each(mem: Object in members) {
    if(!(mem is Function))
        continue;

    var func: Function = Function(mem);

    //I want something like this:
    if(func.getName().startsWith("xxxx")) {
        func.call(...);
    }

}

我很难找到很多关于这样做的信息。感谢您的帮助。

最佳答案

你的伪代码接近于做你想做的事。但是,您可以不使用可以获取私有(private)方法的 getMemberNames,而是使用简单的 for..in 循环遍历成员,并使用括号获取成员的值。例如:

public function callxxxxMethods(o:Object):void
{
  for(var name:String in o)
  {
    if(!(o[name] is Function))
      continue;
    if(name.startsWith("xxxx"))
    {
      o[name].call(...);
    }
  }
}

关于apache-flex - Actionscript 3 自省(introspection)——函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1208418/

相关文章:

apache-flex - Flex 图形 Assets : SWF or SWC?

actionscript-3 - as3 : draw circle with a hole in it using only actionscript

php - 错误: Dynamically fetching css from CDN with fallback to local copy, 如何解决?

android - 无法在 iOS 上与 Bing Map 交互; Android 不显示折线(Flex 移动应用程序,通过 StageWebView 使用 Javascript API)

apache-flex - 具有可变大小项目的 Flex 容器

actionscript-3 - 在Flex中的运行时向组添加边框

actionscript-3 - 如何检测 AS3 中的数据类型

actionscript-3 - 为什么键入的可选参数的默认值为Null?

C++ 非空函数作为函数的参数

c++全局函数与根据内存的数据成员函数