在程序访问在ActionScript 2.0函数的参数列表 [英] Procedurally accessing a function's parameter list in actionscript 2.0

查看:163
本文介绍了在程序访问在ActionScript 2.0函数的参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经可以让所有的一类功能,通过执行类似以下内容。

I can already get at all of the functions in a class by doing something like the following.

for (var member in obj) {
    if (obj[member] instanceof Function) {
        var f:Function = obj[member];
        ...
    }
}

有没有办法让在动作函数的参数列表?例如,我可以写一个函数,做这样的事?

Is there a way to get at a function's parameter list in actionscript? For example, can I write a function that does something like this?

function getFunctionArguments (f:Function) : Array {
    var argumentArray:Array = new Array();
    for (...) {
        ...
        argumentArray.push({ name:<argumentName>, type:<argument type> });
    }
    return argumentArray;
}

如果是这样,我该怎么填的省略号?

If so, what do I fill in at the ellipses?

推荐答案

Nosirree。我想给你一个解决办法,但没有办法反思这样一个函数的签名。

Nosirree. I'd like to give you a workaround, but there's no way to introspect a function's signature like this.

你可以做的是,当函数实际上的名为的,里面可以通过参数浏览无关的签名,通过查看参数对象。如下所示:

What you can do is, when the function is actually called, inside it you can browse through the arguments irrespective of the signature, by looking into the arguments object. As in:

function doSomething() {
    if (arguments.length > 0) {
         if (typeof arguments[0] == "string") {
             ....
         }
    }
}

等。但即便如此,有没有办法找出在函数签名的参数名称(这工作正常,即使有在签名中没​​有参数,如上)。

and so on. But even then there's no way to find out the name of the arguments in the function signature (and this works fine even if there are no arguments in the signature, as above).

这篇关于在程序访问在ActionScript 2.0函数的参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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