Retrieving jQuery.data() values from within setInterval
<p>I've been stuck on this problem for a while now. I'm using jQuery's .data() method to store state in a plugin I'm writing. Everything works fine, except for when I try to retrieve these data values from within a setInterval block. I am able to see the jQuery object inside the setInterval block, but I'm not able to see values stored by the data() method.</p>

<pre><code>tminusStart: function() {
  return this.each(function() {
    var $tminus = $(this).data("tminus.state", "running");

    var intervalId = setInterval(function(tm) {
      if ($tminus.tminusIsRunning()) {
        $tminus.tminusDecrementCounter();

        $tminus.data("tminus.settings").tick_event();

        if ($tminus.tminusTimeRemaining() &lt;= 0) {
          $tminus.data("tminus.settings").expiration_event();
        }

        $tminus.text(tminus.tminusTimeRemaining);
      }
      else {
        clearInterval(intervalId);
      }
    }, 1000, $tminus);
  });
}
</code></pre>

<p>In the above code, the $tminus does return the jQuery object alright, but the calls to the functions - which are calling the .data() method - return undefined; so does the .data("tminus.settings") call.</p>

<p>Any help in understanding why .data() isn't working here would be greatly appreciated.</p>

<p>Rewrite of function removing cruft:</p>

<pre><code>tminusStart: function() {
  var tminus = this;
  tminus.data("tminus.state", "running");

  return this.each(function() {
    console.log(tminus.data("tminus.state")); // "running"
    var intervalId = setInterval(function() {
      console.log(tminus.data("tminus.state")); // undefined
    }, 1000);
  });
}
</code></pre>

<p>I need to know why it's undefined in the setInterval block</p>
