JavaScript SetInterval - Pass function pointer instead of String
<p>I have the following code:</p>

<p><code></p>

<pre><code>XService.start = function() {
  setInterval("XService.poll()", XService.pollInterval); }
</code></pre>

<p></code></p>

<p>This works great. However, when I do this (passing function as reference instead of having the string eval'd) it stops working:</p>

<p><code></p>

<pre><code>XService.start = function() {
  setInterval(XService.poll, XService.pollInterval); }
</code></pre>

<p></code></p>

<p>Why? What am I doing wrong? Nothing else changes in my code. I also tried XService.poll() in the second version but no dice either. The documentation I read said leave the () out.</p>

<p>Help?</p>

<p>Edit: XService.poll is a function; XService.pollInterval is a number. Both are declared and assigned correctly.</p>

<p>Edit2: The XService code:</p>

<p><code></p>

<pre><code>XService = {};
XService.pollUrl = "/Poll";
XService.pollInterval = 60000;
XService.poll = function() {
  $.get(this.pollUrl, null, null, "text"); }
XService.start = function() {
  setInterval(XService.poll, XService.pollInterval); }
</code></pre>

<p></code></p>
