title: Waiting for multiple Events
body: <p>I'm currently developing an app mainly for self-education purposes and since I'm still not completely used to js I could use some help for my problem:</p>
  
  <p>In my app I'm using a Javascript library (jqMobi) which is used for DOM manipulation, page transitions, ajax calls etc and I'm also using phonegap to access device features such as the geolocation.</p>
  
  <p>When I start up my app I want to get the geolocation of the device, send an ajax (jsonp) request to my server (including the geolocation of the device) which returns an array of JSON objects which I will use to build up a list.</p>
  
  <p>Before I can get the geolocation I need to wait for phonegap to load. And before using jqMobi to make the ajax call and handle the response I need to wait for it to load as well.</p>
  
  <p>So I basically have to events im listening to</p>
  
  <pre><code>document.addEventListener("DOMContentLoaded",execute_this,false);  //jqMobi is now ready
  document.addEventListener("deviceready", execure_sth, false); //Phonegap is now ready
  </code></pre>
  
  <p>How do I execute a function as soon as both of these events have fired and not before?</p>
  
  <p>If I'd use jQuery I'd make use of its <code>$.Deferred</code> objects and its When ... Then Function but since I don't have access to these I'm looking for an alternative.</p>