Why can't function in JavaScript "Class" call itself?
<p>I can't figure out what is wrong with this code. Firefox's error console tells me: "<em>this.animateImgSlider is not a function</em>".</p>

<p>What I would like is to call <code>this.selectImage()</code> with <code>jsItems[0].selectImage(0)</code> and then have <code>this.animateImgSlider()</code> be called some number of times until <code>selfCall</code> is false:</p>

<pre><code>function WindowItem(inId) {
    this.id = inId;
    this.imgSliderTarget = 0;
    this.imgSlider = document.getElementById("imgSlider"+inId);

    this.animateImgSlider = function() {
        var selfCall = true;
        var currLeft = parseInt(this.imgSlider.style.left, 10);
        if (currLeft &lt; this.imgSliderTarget) {
            currLeft += 8;
            if (currLeft &gt;= this.imgSliderTarget) {
                currLeft = this.imgSliderTarget;
                selfCall = false;
            }
        }
        else {
            currLeft -= 8;
            if (currLeft &lt;= this.imgSliderTarget) {
                currLeft = this.imgSliderTarget;
                selfCall = false;
            }
        }
        this.imgSlider.style.left = currLeft+"px";
        if (selfCall) setTimeout("this.animateImgSlider()", 0);
    }

    this.selectImage = function(inImg) {
        this.imgSliderTarget = -inImg*488;
        this.animateImgSlider();
    }
}
var jsItems = new Array();
jsItems.push(new WindowItem(0));
</code></pre>

<p>This line is the one that throws the error:</p>

<pre><code>if (selfCall) setTimeout("this.animateImgSlider()", 0);
</code></pre>
