title: Declaring a member function in JS
body: <p>I've tried two ways to declare a member function in JS:</p>
  <pre><code>function init() {
      var name = &quot;Mozilla&quot;;
      function displayName() {
          alert(name);
      }
  }
  a = new init();
  a.displayName()
  </code></pre>
  <p>And</p>
  <pre><code>function init() {
      var name = &quot;Mozilla&quot;;
      displayName = function() {
          alert(name);
      }
  }
  a = new init();
  a.displayName()
  </code></pre>
  <p>The first method told me that <code>displayName()</code> is <code>undefined</code>. The way I see it a variable of type <code>Function</code> with name <code>displayName</code> is created, and thus it should work.
  Any one care to explain why it didn't work?</p>