Archive for February, 2008

Actionscript splat (argument unpacking)

Thursday, February 14th, 2008

In actionscript there is no splat operator or argument unpacking.

In the case where you want to proxy calls to vararg methods you have to use the Function#apply() method.

var array:Array = [];
var stuffToAdd:Array = [ 1, 2, 3, 4 ];
 
array.push.apply(array, stuffToAdd);

It would be nice to have a splat/unpack operator:

array.push(*stuffToAdd);
// Or
array.push(... stuffToAdd);

The ecma mailing list discussed this use of super.apply(this, arguments). And specifically regarding argument unpacking in AS3:

We dropped this from AS3 for lack of evidence for its need.

I think any language with (... args) to Array needs the Array to (... args) if not for anything other than completeness. Does anyone know if this is planned for ES4 at least?