Javascript Different Behaviour when Executing Function vs Code
<p>I'm working on programming a small control panel system, part of which involves some multi-window management. I've written a nice class, and everything works fine, except when I try to close it. For example, I have this function:</p>

<pre><code>var topwin = "something";
function closeTop() {
    for (var i = 0; i &lt; links.length; i++) {
        if (links[i].fetch == topwin) {
            links[i].close();
            break;
        }
    }
}
</code></pre>

<p>When I define the function by pasting it into the console, it works and behaves correctly. But, just being included in window.js along with everything else, it does not work :it misbehaves and closes ALL windows. Idas?</p>

<p><strong>Edit</strong>: More code</p>

<pre><code>this.close = function () {
    $("a[href='"+this.fetch+"']", "#windowlist").css({height: "0px", padding: '0px 20px', margin:'0px'});
    var me = this.me;
    var fetch = this.fetch;
        setTimeout(function() {
            me.remove();
            $("a[href='"+this.fetch+"']", "#windowlist").remove();
            deleteme = fetch;
            sendtotop(links[0].fetch);
            update();
        }, 300);
}
</code></pre>

<p>-</p>

<pre><code>function update () {
    thread = "";
    for (var i = 0; i &lt; links.length; i++) {
        if (deleteme==links[i].fetch) {
            links.splice(i, 1);
            deleteme = null;
            i--;
            continue;
        }
        thread += '&lt;li&gt;&lt;a href="'+ links[i].fetch +'"&gt;'+ links[i].name +'&lt;span&gt;x&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;';
    }
    $("#windowlist").html(thread);
}
</code></pre>
