JavaScript dynamic function name
<p>I need to dynamically assign the name of a function to an element of an associative array. This is my attempt which does not work.  The problem I am asking for help with is here where I try to call the function: <code>cr['cmd1'](x)</code>;</p>

<pre><code>&lt;!DOCTYPE html&gt;

&lt;html&gt;
&lt;head&gt;
    &lt;script type="text/javascript"&gt;
        var cr =[];
        var x = 5;
        cr['cmd1'] ='foo';
        var msg = cr['cmd1'](x);  
        alert(msg);

        function foo(y){
            return y;
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>Edit:</strong> I being passed a string here <code>cr['cmd1'] ='foo';</code> that I cannot control. That is why I have to work with a string as a starting point from an external application.</p>
