You should use eval
only once to get the function, then do everything with it in a variable.
var args = input.substr(1).split(/\s+/);
var fn = eval(args[0]);
if (typeof fn == 'function' && typeof fn.prototype.action == 'function') {
var command = new fn();
command.action(args);
} else {
alert('"'+args[0]+'" could not be evaluated to a valid command.');
}
return true;
If those constructors are global variables, you also can access them as a property of the window
object:
var fn = window[ args[0] ];