I've got a function wich can accept a varible number of parameter with a rest operator.
I want create an object passing the argument collected with the rest operator directly to a constructor without create an object and call an initializing function and without passing the entire array but the parameters ah I do with apply() function.
Is it possible ? Using apply doesn't work.
public function myFunc(...arg) {
// something link "new MyClass.apply(args)"
return new MyClass();
}
Well this led me to an interesting long research!
I found this neat SWC file filled with utils for mimicking the AS2 eval(): http://www.riaone.com/products/deval/index.html
And here's a proof of concept that what you're looking for might actually work:
Sorry for the bits of dependencies (Like my XString class for easy sub-replacements) but it does work in theory. The only issue would be passing object references as argument entries. But then again... the r1.deval.D class might be able to take it... hmm.
Anyways, thought maybe this would be worth sharing.
Unfortunately no. There is no way to make apply work for constructor. What is done generally is to prepare a number of call based on the number of arguments :
well there's also this
and call it through
myFunc({id:33,name:'jo')
you could then pass the object, or is this too far from what you're looking for?
I'm searching for the answer too, but too sad to see the answer is no....
Here's my current (not so good) way to do this kind of stuff, hope some of you interest: