Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 variable length argument expand to call another function with var length args

how to do this

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 wish it call foo(1,2,3), but it call foo(1,[2,3])

like image 758
guilin 桂林 Avatar asked Oct 24 '22 14:10

guilin 桂林


1 Answers

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

If foo and bar are declared in the same class <scope> should be this, otherwise it should be the instance of the class declaring foo and if foo is a global function it should be null

foo.apply( this, args );
//-- or --
foo.apply( myFooInstance, args );
//-- or --
foo.apply( null, args );
like image 196
Creynders Avatar answered Oct 29 '22 22:10

Creynders