Use string to call function method?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1893277/how-to-convert-a-string-value-to-a-variable-in-javascript">How to convert a string value to a variable in javascript?</a>  </p>
</blockquote>



<p>In Javascript, I have an object that looks like this:</p>

<pre><code>clock = function(){
    this.load = function(){
        alert("once");
    }

    this.once = function(){
        alert("load");
    }
}
var clock =  new clock();
</code></pre>

<p>On the page load, I call the <code>load()</code> function within the clock object like so</p>

<pre><code>clock.load();
</code></pre>

<p>When the user clicks a link, however, I need to be able to run <code>clock.once()</code>. Calling it like this is fine, but does not fit the dynamic needs of what I'm doing.</p>

<p>Let's say I need to call <code>clock.once()</code> when the user clicks an <code>&lt;a&gt;</code> tag:</p>

<pre><code>$("a").click(function(){
    var id = $(this).attr("href").match(/[a-zA-Z]+/g);
    [id].once();
}
</code></pre>

<p>I figured that would work, where the object that the <code>once()</code> function is being called from is grabbed from the string <code>id</code>. </p>

<p>When running this, however, I get the following error:</p>

<blockquote>
  <p>Uncaught TypeError: Object clock has no method 'once'</p>
</blockquote>

<p>Manually calling <code>once()</code> by using <code>clock.once()</code> works fine.</p>
