title: JavaScript common method to multiple existing constructors
body: <p>I am rather new to Javascript's way of dealing with constructors,methods and prototypes.</p>
  
  <p>I want to create two constructors that have many different custom methods, but also have some methods in common. Currently I do things like this:</p>
  
  <pre><code>function PlayerWhite(n,s) {     this.name = n; this.state = s;}
  
  function PlayerBlack(n,c) {     this.name = n; this.county = c; }
  
  PlayerWhite.prototype.showCounty = function() { alert(this.county);}
  
  PlayerBlack.prototype.showState = function() { alert(this.state);}
  
  PlayerWhite.prototype.showName = function() {   alert(this.name); }
  
  PlayerBlack.prototype.showName = function() {   alert(this.name); }
  </code></pre>
  
  <p>So the contents of the "showName" method is identical for both constructors.
  The code for "showName" may change and it will be the same for both, so I dont want to do double edits each time I will do an update to the showName method.</p>
  
  <p>Of course, I could use just 1 constructor (function Player), call it twice to build each of the two objects, then assign the common methods to each object and then apply the distinct methods to each object using prototype , but what if I already wrote hundreds of lines of code and I have many objects created from the PlayerBlack and PlayerWhite constructors and I just want to add a new method that could be used between all the existing objects created through PlayerBlack or PlayerWhite?</p>
  
  <p>I tried something like this, but it doesnt work:</p>
  
  <pre><code>PlayerWhite.prototype.showName, 
  PlayerBlack.prototype.showName = function() {   alert(this.name); }
  </code></pre>
  
  <p>I am looking for a solution that would work in nodeJS.</p>