Was looking into ObjectPooling and IOC, and the subject of dynamic invocation of Class constructors came up. I was unpleasantly surprised to find out that Class constructors aren't functions so can't have Function.apply used with them. However the '...(rest)' can make it similar to calling new functions. Here's a comparison of 2 workarounds in use.
Try Richard Lord's construct
or My new2
trace("construct " + construct(Date, [2001,1,1])); trace("new2 " + new2(Date, 2001,1,1));
It's cool how many people into FDT are tackling problems of similar complexity. It's like having a clan.
{ 3 comments… read them below or add one }
Hi, seems it is pretty cool!
Can you describe the code under “construct” and “new2″ functions?
Do you use it e.g. for new2 function:
new rest[0](rest[1], rest[2], rest[3]);
or it’s a bit more tricky?
lolol
Yeah I just had to write this myself.
High five.
Hey Nate! LOL then of course, you and the other 5 people on this planet that care about such esotaric things totally rock!