I\'m looking for a way to construct arbitrary JavaScript objects based on (a) the name of the constructor, and (b) an array containing the arguments. I found this function (
I may end up with this simplified version of Mike's triangle-of-hackery:
function applyCtor2(ctor, args) {
switch (args.length) {
case 0: return new ctor();
case 1: return new ctor(args[0]);
case 2: return new ctor(args[0], args[1]);
// add more cases if you like
}
var jsStr = "new ctor(args[0]";
for (var i=1; i
I'm not using 'apply' here, but I don't miss it. ;-) Any comments?