persistance of javascript functions within an object
<p>I have some functions that only return values if some underlying 'stuff' in the dom has changes, as so:</p>

<pre><code>    function getFoo() {

        if (typeof this.prev === "undefined") {
            this.prev = null;
        }
 // calculate x

        if (x != this.prev) {
            this.prev = x;
        return this.prev;
        } else {
        return;
        }
    }
</code></pre>

<p><code>foo</code> returns none if the computer var <code>x</code> hasnt changed. This seems to work fine when called from the console. </p>

<p>Next, I wrapped this in an object so i could sequentially call similar functions:</p>

<pre><code>function bar () {
    this.plugins = {
        foo: getFoo
    };

    for (var attr in this.plugins) {
        if (this.plugins.hasOwnProperty(attr)) {
            console.log(this.plugins[attr]());
        }
    }
</code></pre>

<p>The strange thing is that when I call <code>bar()</code> now, the underlying functions (such as <code>getFoo</code>) always return values -- even if the underlying stuff in the dom hasnt changed. it seems that the functions are destroyed upon use (in the <code>plugin</code> object) -- how can i persist these?</p>
