title: Return value to parent function, how to wait for asynchronous function
body: <p>I have Following code, I am checking height and width of image.
  this is a part of script. Please help me for this. Thanks in advance</p>
  
  <pre><code>_filesCheck: function() {    
                  var result = false;
  
                      if(n.ftype=='image')
                      {
                              var reader = new FileReader();
                              //Read the contents of Image File.
                              reader.readAsDataURL(f.files[0]);
                              reader.onload = function (e) {
                                  //Initiate the JavaScript Image object.
                                  var image = new Image();
  
                                  //Set the Base64 string return from FileReader as source.
                                  image.src = e.target.result;
  
                                  //Validate the File Height and Width.
                                  image.onload = function () {
                                      var height = this.height;
                                      var width = this.width;
                                      if (height != n.hsize &amp;&amp; width != n.wsize) {
                                          alert("Width and Height must "+n.wsize+"x"+n.hsize+"");
                                          result = false;
                                          return false;
                                      }
                                      /*alert("Uploaded image has valid Height and Width.");*/
                                      result = true;
                                      return true;
                                  };
  
                              }
  
                              alert(result);                          
  
                          return result; }}
  </code></pre>
  
  <p>I want to get true or false in result. But it always give me false. and it get alert before the condition in function</p>