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

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -