title: Converting a string into function in javascript
body: <p>I've done a bit of googling round but this particular problem is a little too similar to the "how do i evaluate function names from strings" so I'm having trouble finding a solution, I want to convert a string into a function so say i had something like:</p>
  
  <pre><code>for (var i = 0; i &lt; someNumber ; i++) {
      var foo = "function() { someObject.someOtherFunctionCall(" + i + ") }";
      someArray[i] = foo;
  }
  </code></pre>
  
  <p>how would I typecast foo so I could call</p>
  
  <pre><code>someArray[0]();
  </code></pre>
  
  <p>I need the value baked into the function, any ideas?</p>
  
  <p><strong>EDIT: I just substituted "value" for "i" apologies for the confusion</strong></p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Ok, I have accepted icktoofay answer because it works, to answer most of your questions and concerns; I have tried most of the methods suggested all of which either didn't pass the variable to the calling locations scope or required closures that persisted with the last functions variable value, unfortunately I don't have control over the rest of the code so I cant make modifications to the location the function eventually gets called.</p>
  
  <p>This is probably a temporary solution; I'm aware of how ugly parsing strings for functions is. as far as browser compatibility goes this will only ever run in one environment, so I think we're pretty safe there.</p>
  
  <p>Anyway, thanks again for the prompt answers and discussion. </p>