javascript - Alternative to eval for accessing object by string name? -


i have following

eval(id+' = new myobject()'); 

and want access resulting object , methods. with

myobject = eval(id); myobject.mymethod(); 

but elegant alternatives there using eval?

assume id intended global object , you're executing in browser,

window[id] = new myobject(); myobject = window[id]; myobject.mymethod(); 

or modify code store id object.

var objectstore = {};  objectstore[id] = new myobject(); myobject = objectstore[id]; myobject.mymethod(); 

Comments

Popular posts from this blog

haskell - Using filter on an item in a list? -

c# - When does PreApplicationStartMethod actually get triggered to run? -

tomcat6 - Exception when stopping container for a with Spring + Quartz + Tomcat web application -