title: Access namespaced javascript object by string name without using eval
body: <p>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.</p>
  
  <p>Originally I was evaluating (<code>eval([string])</code>) and everything was fine. Recently I was updating the function to not use <code>eval</code> for security peace of mind, and I ran into an issue with namespaced objects/functions.</p>
  
  <p>Specifically I tried to replace an <code>eval([name])</code> with a <code>window[name]</code> to access the object via the square bracket syntax from the global object vs <code>eval</code>.</p>
  
  <p>But I ran into a problem with namespaced objects, for example:</p>
  
  <pre><code>var strObjName = 'namespace.serviceArea.function';
  // if I do
  var obj = eval(strObjName); // works
  
  // but if I do
  var obj = window[strObjName]; // doesn't work
  </code></pre>
  
  <p><strong>Can anyone come up with a good solution to avoid the use of <code>eval</code> with namespaced strings?</strong></p>