Best way to get a constructor function for its namespaced, string representation in JavaScript
<p>If I have a sting such as <code>"AppNamespace.SomeObject.ClassName"</code> and I know that the string represents and actual constructor function, what is the best/recommend way of getting that to use in a statement like <code>var foo = new AppNamespace.SomeObject.ClassName</code>?</p>

<p>I could do:</p>

<pre><code>var s = "AppNamespace.SomeObject.ClassName"
var foo = new (eval(s))
</code></pre>

<p>or something like:</p>

<pre><code>var parts = "AppNamespace.SomeObject.ClassName".split(".")
var foo = new (window[parts[0]][parts[1]][parts[2]])
</code></pre>

<p>but I'm wondering if there are better solutions that don't involve <code>eval</code> or having to split the string and loop through its parts. Does anyone have any ideas? If not, based on the two solutions I've proposed, what are the pros and cons of each?</p>
