title: Variables in a Javascript module visible outside of it?
body: <p>To start, I'm coming from a .NET world, where there are static classes (C#, also known as modules in VB) and instance classes - those you can instantiate.</p>
  
  <p>This question is about Javascript, where I'm trying to recreate the pattern I already know and make a module / static class. Here is the code:</p>
  
  <pre><code>var MyModule = {
      variable1: 0,
      variable2: 1,
      method1: function() {
          //code goes here
      },
      method2: function() {
          //mode code goes here
      },
      method3: function() {
          //and some more just to prove the pattern        
      }
  }
  
  method1(); //error - no such method - ok, good, I expect that
  variable1 = 5; //silently assigns a variable inside MyModule to 5 ?
  </code></pre>
  
  <p>Please explain why methods declared inside a namespace are not visible, but variables are ? Also, is there a way to prevent those variables from being visible outside of <code>MyModule</code>, even in the same script ?</p>