How to avoid global variable with incrementing function?
<p>Here is my self-executing function:</p>

<pre><code>var incrementInt = (function() {
    var manyOut = 10;

    if(incInt) {
        incInt+=manyOut;
    } else {
        var incInt = 0;
    }

    return {
        s: incInt,
        m: manyOut
    };
})();
</code></pre>

<p>I have privatized the variables incInt and manyOut, and tied the variable incrementInt to the returned object.</p>

<p>My goal is to create a function that returns an object where one property is an integer that increments every time that it is called. I would like the incrementing variable to have the most narrow scope possible.</p>

<p>My problem with the solution I have above is that the variable incInt is re-initialized every time the function is called. Due to its scope within the function, the variable is destroyed automatically.</p>
