Call function under object from string
<p>I have a script which creates a drag-and-drop uploader on the page from a div. My DIV will look something like</p>

<pre><code>&lt;div class="well uploader"
    data-type="image"
    data-callback="product.addimage"
    data-multi="1"&gt;&lt;/div&gt;
</code></pre>

<p>Then I'll have a function something like</p>

<pre><code>var product = new function(){
    /* Some random stuff */
    this.addimage = function(image){
        alert('W00T! I HAZ AN IMAGE!');
    }
    /* More random stuff */
}
</code></pre>

<p>When the upload is complete, I need to call the function in <code>data-callback</code> (In this example, product.addimage). I know with global functions you can just do <code>window[callback]()</code> but I'm not sure the best way to do this with functions under objects.</p>

<p>My first thought was to do something like*</p>

<pre><code>var obj = window;
var parts = callback.split('.');
for(part in parts){
    obj = obj[parts[part]];
}
obj();
</code></pre>

<p>but that seems a bit dirty, is there a better way without using eval because eval is evil?</p>

<p><sub>I haven't tested this so I have no idea if it will work</sub></p>
