title: image.onload function with return
body: <p>I have a JS function where a value is computed and this value should be returned but I get everytime <code>undefined</code> but if I <code>console.log()</code> the result within this function it works. Could you help?</p>
  
  <pre><code>function detect(URL) {
      var image = new Image();
      image.src = URL;
      image.onload = function() {
          var result = [{ x: 45, y: 56 }]; // An example result
          return result; // Doesn't work
      }
  }
  
  alert(detect('image.png'));
  </code></pre>