What are the differences between these two javascript cases?
<pre><code>var foo1 = function () {
   return {
        init: function () {
            alert(this+" hello foo1");
        }
    };
}();

var foo2 = {
    init: function() {
        alert(this+" hello foo2");
    }
};

foo1.init()
foo2.init()
</code></pre>

<p>The differences I see are:</p>

<ul>
<li>the first is "closure-style", while the second is not.</li>
<li>the first defined a factory function (*) which creates an object and binds the result of this factory to <code>foo1</code>, the second instead is a plain singleton, and you cannot have more instances unless you do .prototype hacking.</li>
</ul>

<p>Are there any other differences ? <code>this</code> binding behavior ? unexpected browser detonations ? crying kittens ?</p>

<p>(*) In other words, I could do something like</p>

<pre><code>var fooFactory = function () {
   return {
        init: function () {
            alert(this+" hello foo1");
        }
    };
}

var foo=fooFactory();
var bar=fooFactory();
</code></pre>

<p>and <code>foo</code> and <code>bar</code> are now two different instances of the same "class" (actually, they are just two Objects that "happen" (by construction) to have the same interface).</p>
