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])
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With