Results 1 to 3 of 3
  1.    #1  
    I was wondering why the following code wouldn't work:

    function FirstAssistant() {

    }

    FirstAssistant.prototype.setup = function() {
    this.total=0;
    this.controller.get('count').update(this.total);

    setInterval(this.updateTotal(),100);
    }

    FirstAssistant.prototype.updateTotal = function() {
    this.total++;
    this.controller.get('count').update(this.total);
    }
    Assuming I have the following code in the html:

    <div id="main" class="palm-hasheader">
    <div class="palm-header">Counter</div>
    <div id="count" class="palm-body-text">count</div>
    </div>
    The result is a bit of text that just reads '1' instead of counting up once ever 100 milliseconds.

    I'm very new to javascript unfortunately. My background is primarily in C# and Java. Any help would be greatly appreciated! Thanks!
  2. #2  
    Your setinterval should look more like this.

    window.setInterval(this.updateTotal.bind(this), 5000);
  3. mosdl's Avatar
    Posts
    781 Posts
    Global Posts
    787 Global Posts
    #3  
    The problem is:

    setInterval(this.updateTotal(),100);

    you are calling the method - you want to pass in a reference, just as the previous post mentions.

Posting Permissions