title: Module Pattern: var module = new function() {...} vs. var module = (function () {...}());
body: <p>The Title is a very shorthand to the actual comparison I will give below.
  I'm delving into JavaScript and also read about the Module Pattern (<a href="http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html" rel="nofollow">JavaScript Module Pattern: In-Depth</a> and <a href="https://toddmotto.com/mastering-the-module-pattern/" rel="nofollow">Mastering the Module Pattern</a>)</p>
  
  <p>An implementation of my own of the Module Pattern was slightly different than the described pattern in the links above.</p>
  
  <p>My implementation:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var smath1 = new function () {
   // "private fields"
   var answer = new Number(42);
  
   // "public fields"
   this.PI = new Number(3.141592653589793);
  
   // "private functions"
   function getHalfTheAnswer() {
    return answer / 2;
   };
  
   // "public functions"
   this.sum = function (a, b) { return new Number(a) + new Number(b) };
   this.mul = function (a, b) { return new Number(a) * new Number(b) };
   this.getTheAnswer = function () { return answer; };
   this.calcTheAnswer = function () { return getHalfTheAnswer() * 2 };
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm interested in how this is different (technically/logically) from the Pattern described in the links...</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var smath2 = (function () {
  
   var my = {};
  
   // "private fields"
   var answer = new Number(42);
  
   // "public fields"
   my.PI = new Number(3.141592653589793);
  
   // "private functions"
   function getHalfTheAnswer() {
    return answer / 2;
   };
  
   // "public functions"
   my.sum = function (a, b) { return new Number(a) + new Number(b) };
   my.mul = function (a, b) { return new Number(a) * new Number(b) };
   my.getTheAnswer = function () { return answer; };
   my.calcTheAnswer = function () { return getHalfTheAnswer() * 2 };
  
   return my;
  }());</code></pre>
  </div>
  </div>
  </p>
  
  <p>...and what makes the second approach superior/preferable to the first, if so at all?</p>
  
  <p>The usage would be exactly the same as well as the behavior as far as I could see in my tests. See the fiddle: <a href="https://jsfiddle.net/m_scheuringer/dtz2br10/" rel="nofollow">JS Module Pattern</a></p>