title: How can I attach a change event handler to a variable?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript-or-jquery">Listening for variable changes in JavaScript or jQuery</a>  </p>
  </blockquote>
  
  
  
  <p>How can I track if this variable has changed?</p>
  
  <pre><code>var ConditionalFlag = 0;
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>var ConditionalFlag = 0;
  $(ConditionalFlag).change(function () {
      alert("Changed");
  });
  ConditionalFlag++;
  </code></pre>
  
  <p>But to no avail. I have considered using a 25ms timer to check for change like this:</p>
  
  <pre><code>var ConditionalFlag = 0;
  function CheckFlag() {
      if (ConditionalFlag &gt; 0) {
          alert("Changed");
          clearInterval(check);
      }
  }
  var check = window.setInterval("CheckFlag()", 25);
  ConditionalFlag++;
  </code></pre>
  
  <p>However, that seems like overkill. Is there a way to attach an event handler to this variable with jQuery or javascript?</p>