Actionscript splat (argument unpacking)
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?
Tags: Actionscript, argument, splat, unpacking
February 14th, 2008 at 9:33 pm
Totally. The splat turns out to be a really useful little idiom for Ruby.
Have you asked Adobe?
http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
e
February 14th, 2008 at 9:33 pm
I ran into this last week. I have a base class that takes a … rest argument at the end of its constructor. It has a subclass which also takes … rest at the end of its constructor. Currently the base class has to inspect rest[0] to see if it’s an Array, but that’s only OK because none of the expected arguments are Arrays.
If I understand your post correctly, I could be using function.apply() in some circumstances, but I’m not sure that would work in a constructor call to super?
Ack.