Image fires onload event, but image is still undefined
<p>I have a fiddle located <a href="http://jsfiddle.net/jlowgren/dpDXp/" rel="nofollow">here</a> illustrating my problem, namely that when I load images using the <code>Image</code> object, <code>onload</code> gets called but the returned object is still <code>undefined</code>.</p>

<p>Here's the code in case the fiddle were to disappear into the void:</p>

<pre><code>var ImageManager = function() {
    var _images = [], 
        _loaded = 0;

    var precache = function(imageArray) {
        if (!(imageArray instanceof Array)) {
            return;
        }

        for (var i = 0; i &lt; imageArray.length; i++) {
            if (typeof imageArray[i] !== 'string') {
                continue;
            }

            _images[i] = new Image();
            _images[i].onload = function() { 
                _loaded++;
                document.write('&lt;p&gt;Successfully loaded: ' + imageArray[i] + ' [' + _loaded + '/' + imageArray.length + ']&lt;/p&gt;'); 
            }
            _images[i].onerror = function() {
                document.write('&lt;p&gt;Unable to load: ' + imageArray[i] + '&lt;/p&gt;'); 
            }
            _images[i].src = imageArray[i];
        }
    };

    var get = function(imagePath) {
        if (!_images.hasOwnProperty(imagePath)) {
            document.writeln('&lt;p&gt;' + imagePath + ' isn\'t precached!&lt;/p&gt;');
            return null;
        }

        return _images[imagePath];
    };    

return { get: get, precache: precache }
};

// Test case starts here:

var testImages = [
    'http://jsfiddle.net/img/logo.png',
    'http://jsfiddle.net/img/logo.png',
    'http://jsfiddle.net/img/logo.png'
];

var imageManager = new ImageManager();
imageManager.precache(testImages);
</code></pre>

<p>Sample output:</p>

<blockquote>
  <p>Successfully loaded: undefined [1/3]</p>
  
  <p>Successfully loaded: undefined [2/3]</p>
  
  <p>Successfully loaded: undefined [3/3]</p>
</blockquote>

<p>As per usual, it's likely something obvious I'm overlooking. Aid me, ye all-knowing oracles.</p>
