Javascript with new or not
<p>I have the following function </p>

<pre><code>var myInstance =  (function() {
  var privateVar = 'Test';

  function privateMethod () {
    // ...
  }

  return { // public interface
    publicMethod1: function () {
      // all private members are accesible here
        alert(privateVar);
    },
    publicMethod2: function () {
    }
  };
})();
</code></pre>

<p>what's the difference if I add a new to the function. From firebug, it seems two objects are the same. And as I understand, both should enforce the singleton pattern.</p>

<pre><code>var myInstance =  new (function() {
  var privateVar = 'Test';

  function privateMethod () {
    // ...
  }

  return { // public interface
    publicMethod1: function () {
      // all private members are accesible here
        alert(privateVar);
    },
    publicMethod2: function () {
    }
  };
})();
</code></pre>
