PDA

View Full Version : Passing a ...rest to a ...rest parameter


rfkrocktk
05-22-2008, 12:43 AM
Hi, I'm trying to extend the functionality (not extend the class itself) of the netconnection.call() function by enclosing a netconnection instance in a class.
What I'm attempting to do is have a function that I have defined as "call" make a call to mynetconnection.call("", null, ...rest). For example:

public function call(method:String, ...rest):void {
this.mync.call(method, null, rest);
}

I have tried repeatedly to do this, and it's not working. The rest parameter feeds the parameters into an array, but is there any way to undo that on the inside of the method and pass a pseudo-list of parameters to nc.call() so that it will see it correctly?

Is it possible to duplicate the functionality of a ...rest parameter into another function?

- TK

wvxvw
05-22-2008, 05:33 AM
public function call(method:String, ...rest):void {
this.mync.call.apply(this, [method, null].concat(rest));
}
But I'm not sure about the scope you want the function to have, I've set it to 'this', but may be you need something different. Is 'call' here a Function.call() method or some custom function of mync? (or is mync an instance of something that has call() method?)
Anyway, consider this scheme:
function myFunction(a:String, ...rest):void {
myOtherFunction.apply(this, [a].concat(rest));
}
function myOtherFunction(...rest):void {
for (var i:int = 0; i < rest.length; i++){
trace(rest[i]);
}
}

rfkrocktk
05-22-2008, 08:16 PM
Awesome, that worked perfectly.