我需要调用一个可变参数函数:
function doSomething(... args): Object {
// do something with each arg
}
但是,我正在为此动态构建参数:
var someArgs: Array = ['a', 'b', 'c'];
doSomething(someArgs);
问题是,当我以这种方式调用函数时
args
最终成为具有 someArgs
的 1 元素数组作为第一个元素,而不是一个三元素数组。怎么打电话
doSomething
与 someArgs
作为参数数组?(对于搜索引擎,这是参数解包)
最佳答案
使用 Function.apply。
像这样:
doSomething.apply(null, someArgs);
如果 doSomething 是类的方法,则传入该类而不是 null。
关于apache-flex - 如何在 ActionScript 中使用数组调用可变参数函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1262199/