title: (Revealing) Module Pattern, public variables and return-statement
body: <p>I'm trying to understand how <em>public` properties</em> in the <strong>(Revealing) Module Pattern</strong> work. An advantage pointed out by <a href="https://carldanley.com/js-revealing-module-pattern/" rel="nofollow noreferrer">Carl Danley "<em>The Revealing Module Pattern</em>"</a> is:</p>
  
  <blockquote>
    <p>Explicitly defined public methods and variables which lead to increased readability</p>
  </blockquote>
  
  <p>Let's take a look at this code (<a href="http://jsfiddle.net/z775e527/" rel="nofollow noreferrer">fiddle</a>):</p>
  
  <pre><code>var a = function() {
      var _private = null;
      var _public = null;
      function init() {
          _private = 'private';
          _public = 'public';
      }
      function getPrivate() {
          return _private;
      }
      return {
          _public : _public,
          init : init,
          getPrivate : getPrivate,
      }
  }();
  
  a.init();
  console.log( a._public ); // null
  console.log( a.getPrivate() ); // "private"
  </code></pre>
  
  <p>It returns <code>null</code> when calling <code>a._public</code>. I now can manipulate that public property, like <code>a._public = 'public';</code>. But I can't change it from within my object. Or at least those changes aren't passed through. I was kinda expecting it to be <code>"public"</code> as it was updated by the <code>init</code>-method before.</p>
  
  <p>Does this actually mean, that I can't have any methods, that handle <em>public</em> properties? Then <em>public</em> properties in this pattern make little sense, right? I also tried this without luck (<a href="http://jsfiddle.net/owztvv5m/" rel="nofollow noreferrer">fiddle</a>):</p>
  
  <pre><code>return {
      _pubic : _public,
      init2 : function() {
          _public = 'public';
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Last, but not least, I have a question regarding the whole <code>return</code> statement. Why isn't it possible to just use <code>return this;</code> to make everything public? As <code>this</code> should be the context of the self-invoked function, shouldn't it just return eveyrthing in it? Why do I have to create another object, that is returned? In this <a href="http://jsfiddle.net/xusznnw6/" rel="nofollow noreferrer">fiddle</a> it returns the <code>window</code> object.</p>