使用反射找出 ActionScript 函数是否具有可变参数/可选参数?
给定一个 ActionScript Function 对象,是否有任何方法可以确定该函数是否具有一个或多个可选参数或 vararg 参数? length
属性似乎返回接受的最小参数数量:
function vararg(a:*, b:*, ...rest):void {}
function optional(a:*, b:* = null, c:* = null):void {}
trace(vararg.length); // 2
trace(optional.length); // 1
我尝试反映函数属性:
for (var name:String in optional) {
trace(name + ": " + optional[name];
}
但是这根本没有输出任何内容。
有谁知道如何通过反思发现这些信息?
Given an ActionScript Function object, is there any way to determine whether that function has one or more optional parameters, or vararg parameters? The length
property seems to return the minimum number of arguments accepted:
function vararg(a:*, b:*, ...rest):void {}
function optional(a:*, b:* = null, c:* = null):void {}
trace(vararg.length); // 2
trace(optional.length); // 1
I've tried reflecting over the function properties:
for (var name:String in optional) {
trace(name + ": " + optional[name];
}
However this did not output anything at all.
Does anyone know how to discover this information through reflection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我可以让你靠近一点,但不能一直。
如果您在具有该函数的对象上调用
describeType
并且这些函数是公共的,您将获得有关这些函数的更多信息:这将为您提供有用的输出:
它也不会告诉您有关 <代码>...休息 可变参数。因此,有两个警告:它们必须是公开的,并且您不会获得可变参数...但是您确实获得了更多信息...
我不确定您是否能够获得比这更多的信息。
我一直认为
describeType
也需要能够反映私有内容......但可惜。Well, I can get you a little bit closer, but not all the way.
If you call
describeType
on the object that has the function AND those functions are public, you will get more information about the functions:This will give you useful output:
It also won't tell you about the
...rest
varargs. So, there are two caveats: they must be public AND you don't get varargs... but you do get a lot more information...I am not sure you will be able to get any more information than this.
I've always thought
describeType
needs to be able to reflect on private stuff as well... but alas.http://bugs.adobe.com/jira/browse/FP-1472是将可变参数添加到describeType 的错误。它的优先级为“无”,这并没有给解决这个问题带来太多希望。也许投票会有所帮助。
http://bugs.adobe.com/jira/browse/FP-1472 is the bug to add varargs to describeType. It's got a priority of "none", which doesn't give much hope that this will be fixed. Maybe voting it up will help though.