title: Value undefined inside Callback function
body: <p>I'm using Elastic.js to access ElasticSearch and run query.... I need to run a facet and get the result and use this result for another query... I'm able to get the result of first one and run query using the result, but not able to access the 1st query term inside the second callback due to the problem with execution sequence. If I use setTimeout() of JS im able to get desired result. </p>
  
  <p>So is there any better alternative to setTimeout  ??</p>
  
  <pre><code>for(i in res_week){ 
          if(res_week[i].term !=null){
              var sourceFilter = ejs.TermsFilter("source",res_week[i].term);
                  var data2 = [];
                  var term_temp = res_week[i].term;
                  var count_temp = res_week[i].count;
                  var typesCallback = function(typeResults){
  
                      console.log(typeResults);
                      var temphold = typeResults.facets.srctype_list.terms;
                      data2.push(temphold);
                      console.log(term_temp);
  
  
                  };
                  data.push({"list":data2});
                  var temp_r = ejs.Request()
                          .indices(index)  
                          .types(type)
                          .facet(listfacet
              .facetFilter(ejs.AndFilter([timeLimit,sourceFilter])));
  
                  console.log(temp_r);
                  temp_r.doSearch(typesCallback);
  
  
  
                          }
  </code></pre>
  
  <p>Here I'm not able to access res_week[] 's terms inside typesCallback function and it says undefined, by using a temporary variable i get those terms inside the function but not in the first iteration, but from second iteration only. </p>