title: Undefined variables within nested function
body: <p>I have a http post request which returns ID. I then try to pass that ID into another function. However, inside the next function I have a timeout that will loop the function to check the status. The ID returns undefined each time inside the timeout function.</p>
  
  <p><strong>First Function</strong></p>
  
  <p>Here I have 'res' which is a result from another function. I grab the status ID from the returned json and send it to 'getAlbum'.</p>
  
  <pre><code>anotherFunction(res) {
    this.getAlbum(res);
  }
  </code></pre>
  
  <p><strong>GetAlbum</strong></p>
  
  <p>If I do a console log immediately inside this function, it correct emits the correct ID. However, if I do it inside the 'checkAblumStatus' function, the id part is undefined.</p>
  
  <pre><code>getAlbum(id){
  
   var statusID = id.status_id;
  
    console.log('id = ' + statusID) // returns id
  
    var statusIDRequest = 'url' + statusID;
  
    var checkAblumStatus = function (statusIDRequest) {
  
      console.log('statusIDRequest = ' + statusIDRequest) // returns undefined for the ID part
  
      this.http.get(statusIDRequest).subscribe(res =&gt; {
        if (res.status == "completed") {
          // completed
        } else if (res.status == "failed") {
          // failed
        } else {
          setTimeout(checkAblumStatus, 1000);
        }
      });
    };
  
    setTimeout(checkAblumStatus, 1000);
  }
  </code></pre>
  
  <p>Any help here would be very grateful :)</p>