title: Creating objects dynamically, what's the alternative to eval?
body: <p>I'm trying to create objects dynamically, using <code>eval(string)</code>. I've been unable to find an alternative to using <code>eval</code> or at least something that I could understand.</p>
  
  <p>I'm looping through code that looks like the following, the string varies randomly, picked up for an array of strings which contain objects definitions.</p>
  
  <pre><code>llista[dia] = eval('new Accident_mortal("EP-8", 17, "accident helicopter", 1, 2, 0)');
  </code></pre>
  
  <p>From what I've read all around, using <code>eval</code> is a bad thing, but I can't figure out how else I could do this.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I think Lolo's code is what I need, can I do the following?</p>
  
  <pre><code>var o = [  
      { clazz1: 'Accident_mortal', args: ["EP-8", 17, "accident helicopter", 1, 2, 0] },  
      { clazz2: 'Accident_mortal', args: ["B45", 101, "accident camio", 4, 3, 1] },  
      { clazz3: 'Accident_mortal', args: ["C19", 234, "accident tot terreny", 2, 1, 1] }  
  }
  </code></pre>
  
  <p>Up to 9 objects inside var o, and then use the code he proposes to generate random objects from these 9 definitions.</p>