title: Javascript pass variable through recursive function
body: <p>I am trying to create a recursive function in Javascript. But in order to loop my XML file properly I am trying to pass the right value taken from the XML <code>length</code> and pass it to the <code>setTimeout</code> function.
  The problem is that the <code>setTimeout</code> ( <code>setTimeout('cvdXmlBubbleStart(nextIndex)', 3000);</code> 
  )function does not get the value of <code>nextIndex</code> and thinks it is <code>undefined</code>. I am sure I am doing something wrong.</p>
  
  <pre><code>jQuery(document).ready(function($) {
  cvdXmlBubbleStart('0');
  });
  
  function cvdXmlBubbleStart(nextIndex) {
      $.ajax({
          url: "cross_video_day/xml/broadcasted.xml",
          dataType: "xml",
          cache: false,
          success: function(d) {
              broadcastedXML = d;
              cvdBubbleXmlProcess(nextIndex);
          }
      });
  }
  
  function cvdBubbleXmlProcess(nextIndex) {
      var d = broadcastedXML;
  //console.log(nextIndex);
      var length = $(d).find('tweet').length;
      if((nextIndex + 1) &lt; length) {
  
  
      nextIndex = length - 1;
  
  
      $(d).find('tweet').eq(nextIndex).each(function(idx) {
          var cvdIndexId = $(this).find("index");
          var cvdTweetAuthor = $(this).find("author").text();
          var cvdTweetDescription = $(this).find("description").text();
          if (cvdTweetAuthor === "Animator") {
              $('#cvd_bubble_left').html('');
              obj = $('#cvd_bubble_left').append(makeCvdBubbleAnimator(cvdIndexId, cvdTweetAuthor, cvdTweetDescription));
              obj.fitText(7.4);
              $('#cvd_bubble_right').html('');
              setTimeout('$(\'#cvd_bubble_left\').html(\'\')', 3000);
          } else {
              $('#cvd_bubble_right').html('');
              obj = $('#cvd_bubble_right').append(makeCvdBubble(cvdIndexId, cvdTweetAuthor, cvdTweetDescription));
              obj.fitText(7.4);
              $('#cvd_bubble_left').html('');
              setTimeout('$(\'#cvd_bubble_right\').html(\'\')', 3000);
          }
  
      });
  
           }else{
           $('#cvd_bubble_left').html('');
              $('#cvd_bubble_right').html('');
           }    
          //broadcastedXMLIndex++;
          setTimeout('cvdXmlBubbleStart(nextIndex)', 3000); 
  }
  </code></pre>