KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I ran into a situation where I need access to a javascript object from the server. The server returns the string name of the function or object and based on other metadata I will evaluate the object differently. Originally I was evaluating ( eval([string]) ) and everything was fine. Recently I was updating the function to not use eval for security peace of mind, and I ran into an issue with namespaced objects/functions. Specifically I tried to replace an eval([name]) with a window[name] to access the object via the square bracket syntax from the global object vs eval . But I ran into a problem with namespaced objects, for example: var strObjName = 'namespace.serviceArea.function'; // if I do var obj = eval(strObjName); // works // but if I do var obj = window[strObjName]; // doesn't work Can anyone come up with a good solution to avoid the use of eval with namespaced strings?
Tags (comma-separated)
Save Edits
Cancel