How to turn a String into a javascript function call (case with objects)
<p>Yeah, there are numerous questions like <a href="http://stackoverflow.com/questions/912596/how-to-turn-a-string-into-a-javascript-function-call">How to turn a String into a javascript function call?</a> or <a href="http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string">How to execute a JavaScript function when I have its name as a string</a>.</p>

<p>But what if we have not a plain function name, but an object property name which in fact is a function?</p>

<p>Like:</p>

<pre><code>var callMe = 'foo.bar.baz';
</code></pre>

<p>and the code expected to be called is:</p>

<pre><code>window.foo = {
    bar: {
        baz: function() {
            alert('Eureka!');
        }
    }
};
</code></pre>

<p>Why I need this: the callback parameter is passed via url and it can (by application design) be either a function name or FQN of object's property.</p>

<p>Any ideas others than <code>eval()</code>?</p>

<p><strong>UPD</strong>:</p>

<p>My final implementation:</p>

<pre><code>var parts = callbackName.split('.'),
    callback;

for (i in parts) {
    if (!callback) {
        callback = window[parts[i]];
    } else {
        callback = callback[parts[i]];
    }

    if (typeof callback === 'undefined') break;
}

if (typeof callback === 'function') {
    callback();
} else {
    console.error('Passed callback is not a valid function');
}
</code></pre>
