AS3 で可変長引数リストをアンパックする方法があるかどうか疑問に思っています。たとえば、次の関数を使用します。
public function varArgsFunc(amount:int, ...args):Array
{
if (amount == 3)
{
return args
}
else
{
return varArgsFunc(++amount, args)
}
}
これを呼び出すと:
var result:Array = varArgsFunc(0, [])
結果には、ネストされた一連の配列が含まれるようになりました。
[[[[]]]]
ここでの問題は、args パラメータが配列として扱われることです。したがって、可変引数リストを持つ関数に渡すと、単一の引数として扱われます。
Scala には、リストをパラメーターのリストに分割するようコンパイラーに指示する :_* 演算子があります。
var list:Array = ['A', 'B', 'C']
// now imagine we have this class, but I would like to pass each list element
// in as a separate argument
class Tuple {
public function Tuple(...elements)
{
// code
}
}
// if you do this, the list will become be passed as the first argument
new Tuple(list)
// in scala you can use the :_* operator to expand the list
new Tuple(list :_*)
// so the :_* operator essentially does this
new Tuple(list[0], list[1], list[2])
配列を引数リストに展開する手法/演算子が AS3 に存在するかどうかを知りたいです。