AS3 variable length argument expands to call another function with arguments of length var

how to do it

function foo(x:*, ...args):* {
}

function bar(x:*, ...args):* {
   foo(x, args); // how to expand args ? the args is an array now
}

how to expand args? when I call bar(1,2,3), I want him to call foo(1,2,3), but to callfoo(1,[2,3])

+5
source share
2 answers
function bar(x:*, ...args):* {
   args.unshift( x ); //add x to the front of the args array
   foo.apply( <scope>, args );
}

If foou must be bardeclared in the same class , otherwise it must be an instance of the class declaring , and if it is a global function, it must be<scope>thisfoofoonull

foo.apply( this, args );
//-- or --
foo.apply( myFooInstance, args );
//-- or --
foo.apply( null, args );
+4
source

I believe this partially answers your question: http://www.flex888.com/574/can-i-have-a-variable-number-of-arguments-in-as3.html

, , , .

-1

All Articles