title: Having trouble with javascript object scope and setTimeout?
body: <p>I've got some code that follows the following structure: </p>
  
  <pre><code>function = roulette(){
  
      _this = this;
      this.spin = spin;
      this.timeoutFunction = timeoutFunction;
  
      this.object1 = {
          x : 0
      }
  
      function spin(){
          if (typeof this.shuffleTimer !== 'undefined') {
              clearTimeout(_this.shuffleStart);
          }
          this.shuffleStart = setTimeout(_this.timeoutFunction(), _this.object1.x);
      }
  
      function timeoutFunction(){
          this.object1.x += 5;
          //do some DOM manipulation here
          console.log(_this.object.x);
          if(this.object1.x &lt; 5000){
            this.shuffleStart = setTimeout(_this.timeoutFunction(), _this.object1.x);
          }
      }
  }
  </code></pre>
  
  <p>It is definitely not working as intended - while the <code>console.log</code> logs that <code>this.object1.x</code> is increasing, it does so way too fast and at a uniform rate, which is not how it would've been working if the <code>setTimeout</code> in <code>timeoutFunction</code> was set off after an increased amount of time each time it was called. </p>