the js immediate function exec sequence
<pre><code>var Gadget = function () {
    // static variable/property
    var counter = 0;
    // returning the new implementation
    // of the constructor
    return function () {
        console.log(counter += 1);
    };
}(); // execute immediately

var g1 = new Gadget(); // logs 1
var g2 = new Gadget(); // logs 2
var g3 = new Gadget(); // logs 3
</code></pre>

<p>I debug this code and the <code>var counter = 0;</code> will not be executed during <code>new Gadget()</code>, and the output is <code>1,2,3</code>. </p>

<pre><code>var Gadget = function () {
    // static variable/property
    var counter = 0;
    // returning the new implementation
    // of the constructor
    return function () {
        console.log(counter += 1);
    }();
}; // execute immediately

var g1 = new Gadget(); // logs 1
var g2 = new Gadget(); // logs 2
var g3 = new Gadget(); // logs 3
</code></pre>

<p>I debug this code the <code>var counter = 0;</code> will be executed during <code>new Gadget()</code>, and the output is <code>1,1,1</code>.</p>

<p>this demo code is in javascript pattern, private static members. I have a little trouble to understand this.</p>
