title: how to call back in asynchronous function in javascript
body: <p>Basically, my application is a PhoneGap app with windows azure service, I have a problem with callback method with javascript.Please check the code below.</p>
  
  <pre><code>checkeventsRegistration = function (azureEid,regid,callback) {
    alert(azureEid + " &lt;&gt; " + regid);
    var client = new WindowsAzure.MobileServiceClient('https://mobbacktest.azure-mobile.net/', 'RvahPxHKoEsGiLdlCYZpHBllvSVQxl66');
    reglog = client.getTable('registrationlog');
    query = reglog.where({ eventid: azureEid, regid: regid });
  
    query.read().done(function (log)
    {
      alert("Log:" + log.length);
    });
    callback(log.length);
  };
  </code></pre>
  
  <p>and i will call this function as below.</p>
  
  <pre><code>checkeventsRegistration(eid, regid, savenum);
  </code></pre>
  
  <p>My issue is this callback method is firing before the <code>query().read()</code>.</p>