Trying to create objects within a for loop
<p>I'm sure there's a really simple solution to this but I can't wrap my head around it. I'm trying to create and array of objects within a for loop like so:</p>

<pre><code>for(var i = 0; i &lt; 100; i++) {
    foos[i] = new Foo(i*10);
    bars[i] = someObject.createBar({
         x : 0,
         y : 0,
         foobar = function() {
              foo[i].a = true;
         }
    });
}
</code></pre>

<p>When trying to run this I get 'cannot set property a of undefined', both foos and bars are declared earlier in the code as globals.</p>

<p>It works fine if I create foos as foos[0] and access through bars[0]. I suspect it's something to do with function level scoping but as far as i can see the arrays should be accessible on the global object....</p>
