Benefits of JavaScript anonymous function with namespaces
<p>Is there any benefit when writing JavaScript classes and namespaces of this...</p>

<pre><code>if(typeof MyNamespace === 'undefined'){
    var MyNamespace = {};
}

(function(){
MyNamespace.MyClass = function(){
    this.property = 'foo'

    return this;
}
}());
</code></pre>

<p>Versus just this...</p>

<pre><code>if(typeof MyNamespace === 'undefined'){
    var MyNamespace = {};
}

MyNamespace.MyClass = function(){
    this.property = 'foo'

    return this;
}
</code></pre>

<p>I have seen the first pattern implemented in a few libraries, and was trying to find how out if there is any added benefit unless some sort of other function was declared inside of the anonymous function in the first example.</p>
