having trouble modifying a timer interval function to also give total duration in javascript
<p>I found this <a href="https://gist.github.com/1185904" rel="nofollow">interval function</a> and I have been using it on my website. However, i need to get the total duration from the interval. I tried modifying it so i could call timer.total_duration to get the total amount of time but when i try running the modified code i get an error saying "Uncaught TypeError: number is not a function" the modified function is:</p>

<pre><code>function interval(duration, fn) {
    this.baseline = undefined
    this.total_duration = 0.0

    this.run = function () {
        if (this.baseline === undefined) {
            this.baseline = new Date().getTime()
        }
        fn()
        var end = new Date().getTime()
        this.baseline += duration

        var nextTick = duration - (end - this.baseline)
        if (nextTick &lt; 0) {
            nextTick = 0
        }
        this.total_duration += nextTick //line giving the error
        (function (i) {
            i.timer = setTimeout(function () {
                i.run(end)
            }, nextTick)
        }(this))
    }

    this.stop = function () {
        clearTimeout(this.timer)
    }
}
</code></pre>

<p>Any idea why I'm getting this error, and how to fix it so I can get the total duration?</p>
