Passing anonymous functions as parameters for later use
<p>I'm having issues with a script that I made for use in HTML5. 
Here is the function</p>

<pre><code>function loadImage(loc,after,para){
        var img = new Image();
        img.src = loc;
        if(typeof(after) != "undefined" &amp;&amp; typeof(para) != "undefined"){
            img.onloadeddata  = after(img,para);
        }else if(typeof(after) != "undefined"){
            img.onloadeddata  = after(img);
        }
        return img;
}
</code></pre>

<p>and here is what is calling it</p>

<pre><code>window.globalFriends[i][2]=loadImage('http://graph.facebook.com/'+window.globalFriends[i][0]+'/picture', function (a){
    updateLoaders();
    loadingDrawPerson(a);});
</code></pre>

<p>What I'm trying to do is send a function as a parameter for it then to be called.
It kinda of works but it a weird way. For example; All the images do get loaded but the onloadeddata either fires the function way to early or the function is getting executed before it gets to the loadImage function.</p>

<p>What are your ideas on my malfunctioning script?</p>

<p>Thank-you for reading
Paul</p>
