Let me first explain the issue piecemeal.
I need to create a constructor function based on the “Factory pattern” – meaning I don’t want to use the ‘new’ operator when I call this constructor. It’s easy, for example…
function Make(x) {
if ( !(this instanceof arguments.callee) )
return new arguments.callee(x);
// do your stuff...
}
BUT, I need this method to accept variable no. of arguments, like this…
function Take(/* ... */) {
// process arguments with 'arguments[]' array-like object
// do your stuff...
}
Now, the PROBLEM is how do i make a constructor that implements the ‘Factory pattern’ AND accepts variable no. of arguments.
If you do this…
function Fake(/* ... */) {
if ( !(this instanceof arguments.callee) )
return new arguments.callee.apply(null, arguments);
// do your stuff...
}
You’ll get an error telling you that apply() method is NOT a constructor. The porblem here is that the ‘new object’ is being passed to apply() method, not to our constructor.