ActionScript 3, … (rest) parameter, finally!

Yesterday I was reading the latest actionscript 3 documentation on adobe labs and I found that they finally introduced the … ( rest) function’s argument, as also described in the ECMA Script 4 specifications.
I say “finally” because it’s since I discovered python *args and **kwds function arguments that I pray for them also in actionscript.
In actionscript3 rest parameter is used for example:

public function log(message:String, ... rest):void
logging.text += message + "\n";
for(var i:uint = 0; i < rest.length; i++)
logging.text += rest[i] + "\n";
log("hello", "spammed", "world");

The reference says about the rest parameter: specifies that a function will accept any number of comma delimited arguments. The list of arguments becomes an array that is available throughout the function body.
Now I just will wait till they will intoduce also the **kwds python equivalent parameter and I will an happy man! 🙂
Read more here

  • delizade

    what is difference between rest and arguments? as i know, we can do same process with “argument”

  • arguments were all the arguments passed to a function, in this way you can define first the n required and typed arguments, and after those the optional arguments

  • i want to overload methods in AS, why they don’t do that… grr..
    but rest parameter is a nice one

  • alessandro

    we’re asking for method’s overload since so many years… I dont know if they will put it one day 🙂