In my node js application I have a variable (name) that contains an object's name; I need to assign that object to another object's property; I do this:
wrapElement[index].model = eval('model.' + name);
Jshint throws a well-documented warning for that (eval can be harmful); I know eval can be dangerous (but in this case i think I'm safe because 'name' is not an input from user) and bad for performance;
In this case do I really need to use eval() or there is a better way to accomplish this assignement?
--- UPDATE -----------------
As suggested below in comments, in this case I can simply do model[name] instead of eval(). The code of this application has been changed just today, keeping models in a separate node module and exported as 'model'; before models were defined in the same file:
Shop = {
...
}
Offer = {
...
}
And the assignement was:
wrapElement[index].model = eval(name);
In this case I was not able to write
something[name]
instead of using eval; In this case, should I include all the models (Shop, Offer, ...) into a wrappingObject in order to write wrappingObject[name] or I can access it with somethingElse[name]?