Set function data into variable using Javascript : <p>I'd like to set the width of an external image (from another url) into a variable, so I can use the newly assigned variable on another function.</p>

<p>The problem is that I get <code>undefined</code> message on the variable, see the code below.</p>

<pre><code>var site_url = 'http://fabricjs.com/assets/1.svg';

function getMeta(url, callback) {
    var img = new Image();
    img.src = url;
    img.onload = function() { callback(this.width, this.height); }
}
var a = getMeta(site_url, function(width, height) { 
    return width; 
});

alert(a); //undefined
</code></pre>

<p>What am I doing wrong, how should I proceed ?</p>
