I have a script that creates new objects based on the value of a form
field. Basically, the code looks like this.
eval ('new ' + objType.value + '(val1, val2, val3');
objType is a select with the different types of objects you can create
as values.
I really don't like using eval, and it's causing problems, like if I
do something like the following:
eval ('localVar = new ' + objType.value + '(val1, val2, val3');
localVar should refer to a variable local to the calling object, but
with the eval approach it ends up being the local variable for the
scope from which the eval was first executed.
I could use a seitch statement, but this approach means I now have an
extra place where I need to change my code so I'd like to afford this
if possible.
Is there another approach to creating a new instance of an object
dependant on the value of some variable?
field. Basically, the code looks like this.
eval ('new ' + objType.value + '(val1, val2, val3');
objType is a select with the different types of objects you can create
as values.
I really don't like using eval, and it's causing problems, like if I
do something like the following:
eval ('localVar = new ' + objType.value + '(val1, val2, val3');
localVar should refer to a variable local to the calling object, but
with the eval approach it ends up being the local variable for the
scope from which the eval was first executed.
I could use a seitch statement, but this approach means I now have an
extra place where I need to change my code so I'd like to afford this
if possible.
Is there another approach to creating a new instance of an object
dependant on the value of some variable?
Comment