title: Passing variables from within object into setTimeout
body: <p>I'm having some interesting issues with passing in variables from within an object into <code>setTimeout</code>. At first, I tried putting the function I was calling from <code>setTimeout</code> on my object so that I wouldn't have to pass any variables into it (I was hoping it could access my object by itself). That didn't work, apparently because the function somehow became global when I called it from <code>setTimeout</code>, and no longer had access to my object's variables. </p>
  
  <p>This was my next attempt, but it doesn't work either:</p>
  
  <pre><code>function MyObj() {
      this.foo = 10;
      this.bar = 20;
      this.duration = 1000;
  
      setTimeout(function(){
          AnotherFunction(this.foo, this.bar)
      }, this.duration);
  }
  </code></pre>
  
  <p>So, how exactly can I pass in a variable into <code>setTimeout</code> from within an object? No, <code>AnotherFunction</code> won't be able to directly access <code>MyObj</code> for various unrelated reasons, so that's out of the question too.</p>