title: How to use "setTimeout" to invoke object itself
body: <p>Why can't I use <code>setTimeout</code> in a javascript object?</p>
  
  <pre><code>Message = function () {
  
      ...
      ...        
  
      this.messageFactory = ...
      this.feedbackTag = document.getElementById('feedbackMessages');
  
      this.addInfo = function (message) {
          var info = this.messageFactory.createInfo(message); // create a div
          this.feedbackTag.appendChild(info);
  
          setTimeout('this.feedbackTag.removeChild(info)', 5000);
          // why in here, it complain this.feedbacktag is undefined ??????
  
      };
  }
  </code></pre>
  
  <p>Thanks for Steve`s Solution, now it will work if the code is as below...
  because the 'this' before was actually pointing to the function within setTimeOut, it cannot rearch Message.</p>
  
  <pre><code>Message = function () {
  
      ...
      ...        
  
      this.messageFactory = ...
      this.feedbackTag = document.getElementById('feedbackMessages');
  
      this.addInfo = function (message) {
          var info = this.messageFactory.createInfo(message); // create a div
          this.feedbackTag.appendChild(info);
  
          var _this = this;
          setTimeout(function() { _this.feedbackTag.removeChild(info); }, 5000);
  
      };
  }
  </code></pre>
  
  <p>But why doesn`t it work if we do this:</p>
  
  <pre><code>Message = function () {
  
      ...
      ...        
  
      this.messageFactory = ...
      this.feedbackTag = document.getElementById('feedbackMessages');
      // public function
      this.addInfo = function (message) {
          var info = this.messageFactory.createInfo(message); // create a div
          this.feedbackTag.appendChild(info);
  
          delayRemove(info);
  
      };
      // private function
      function delayRemove(obj) {
          var _this = this;
          setTimeout(function() { _this.feedbackTag.removeChild(info); }, 5000);
      }
  }
  </code></pre>