Can anyone suggest how to create an arbitrary object at runtime
WITHOUT using the deprecated eval() function. The eval() method works
ok (see below), but is not ideal.
function Client() { }
Client.prototyp e.fullname = "John Smith";
var s = "Client";
eval("var o = new " + s + "();");
alert(o.fullnam e);
Note: I want the type name of the object to be represented as a string
(in this case "Client" -- this is a non-negotiable requirement).
I also tried the following (which appears to fail):
function Client() { }
Client.prototyp e.fullname = "John Smith";
var s = "Client";
var o = new Object();
o.construct = s;
alert(o.fullnam e);
eval() is handy but not future-proof, so any suggestions would be
welcome.
Kind regards,
Steve
WITHOUT using the deprecated eval() function. The eval() method works
ok (see below), but is not ideal.
function Client() { }
Client.prototyp e.fullname = "John Smith";
var s = "Client";
eval("var o = new " + s + "();");
alert(o.fullnam e);
Note: I want the type name of the object to be represented as a string
(in this case "Client" -- this is a non-negotiable requirement).
I also tried the following (which appears to fail):
function Client() { }
Client.prototyp e.fullname = "John Smith";
var s = "Client";
var o = new Object();
o.construct = s;
alert(o.fullnam e);
eval() is handy but not future-proof, so any suggestions would be
welcome.
Kind regards,
Steve
Comment