title: JavaScript setTimeout can't access function variable
body: <p>At least is what I think it happens in this case:</p>
  
  <pre><code>function MyFunc() {
      var people = Array({name: 'Alex', age: 25}, {name: 'Ellen', age: 43});
      for (var i=0; i&lt;people.length; i++) {
          setTimeout(function() { ShowIt(people[i].name) }, 1000); // !!!
      }
  }
  
  function ShowIt(name) {
      alert(name);
  }
  </code></pre>
  
  <p>I get this error <code>Uncaught TypeError: Cannot read property 'name' of undefined</code>, so it looks like inside the <code>setTimeout</code> listener function the <code>people</code> variable is not accessible. Why and how can I fix it?</p>