Actionscript 3 自省——函数名 [英] Actionscript 3 introspection -- function names

查看:31
本文介绍了Actionscript 3 自省——函数名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to iterate through each of the members of an object. For each member, I check to see if it is a function or not. If it is a function, I want to get the name of it and perform some logic based on the name of the function. I don't know if this is even possible though. Is it? Any tips?

示例:

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(...);
    }

}

我很难在这方面找到很多东西.感谢您的帮助.

I'm having a hard time finding much on doing this. Thanks for the help.

推荐答案

您的伪代码已接近执行您想要的操作.但是,您可以使用简单的 for..in 循环遍历成员,而不是使用可以获取私有方法的 getMemberNames,并使用括号获取成员的值.例如:

Your pseudocode is close to doing what you want. Instead of using getMemberNames, however, which can get private methods, you can loop over the members with a simple for..in loop, and get the values of the members using brackets. For example:

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(...);
    }
  }
}

这篇关于Actionscript 3 自省——函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆