title: Javascript: Accessing public method of prototype does not work
body: <p>I want to create a simple class in Javascript with only one public function as follows:</p>
  
  <pre><code>function A(myTitle) { 
      var title = "";
      this.getTitle = function() {
          return title;
      };
      title = myTitle;
  };
  
  var anInstance = new A("first");
  console.log("anInstance.getTitle(): '"+anInstance.getTitle()+"'"); 
  // expecting to return "first"
  </code></pre>
  
  <p>This does work as expected.</p>
  
  <p>Now I want to add this class as a prototype to a new class, that includes a new title variable, so that the getTitle() method returns the value of the variable instead:</p>
  
  <pre><code>var myA = new Object();
  myA.title ="second";
  myA.prototype = anInstance;
  console.log("myA.getTitle(): '"+myA.getTitle()+"'"); 
  // expecting to return "second"
  </code></pre>
  
  <p>But instead of the expected "second", it results in the following error:</p>
  
  <pre><code>TypeError: 'undefined' is not a function (evaluating 'myA.getTitle()')
  </code></pre>
  
  <p>What is the problem with this function access?</p>
  
  <p><strong>Update:</strong>
  The key point for my question is the following: In my application I will create several thousand instances of type "A" and several more of other comparable types. Thus memory efficiency and performance do matter. So I thought it would be great to create the according methods (several more will follow, <code>getTitle</code> is only one example) only once and the "data objects" reference these methods. Is this possible?</p>