Namespacing in Javascript Classes
<p>I'm trying to create a timer in Javascript and I have a specific issue with how I'm implementing it. </p>

<p>Right now  it's like this</p>

<pre><code>function CountUpTimer(seconds,name,targetId,submitButtonId){
this.time = seconds; 
this.currentTime = 0;
this.minutes = Math.floor(seconds/60);
this.submitButtonId = submitButtonId;

this.seconds = seconds - this.minutes*60;
this.currentSeconds = 0;
this.currentMinutes = 0; 
this.targetId = targetId;
this.name = name;
this.isPaused = false; 
this.init = function(){
    setInterval(this.name + ".tick()",1000);
}

this.pause = function(){
    this.isPaused = true;
}
this.unpause = function(){
    this.isPaused = false; 
}
this.tick = function(){
    if(this.isPaused == false){
    if(this.currentTime &lt;= this.time){
        if(this.currentSeconds == 59){
            this.currentSeconds = 0;
            this.currentMinutes++; 
        }
        this.updateTimer();
        this.currentTime++;
        this.currentSeconds++;
    } else{
        this.endTiming();
    }
}
}
</code></pre>

<p>Now, the problem with this is that I can't dynamically create CountUpTimer objects, because I need to know the name of the variable that I am assigning to that object. Is there some way I can work around this - so let's say something like </p>

<pre><code>setInterval(this.tick(),1000);
</code></pre>

<p>?</p>
