title: How to extend a class in JavaScript
body: <p>I'm working on a chess game built in JavaScript. I'm taking an object-oriented approach to it and am having some difficulty working with JavaScript's inheritance. I want there to be a "Piece" abstract class that holds some fields and basic getters/setters such as is this piece black or white. I then want to have classes for each type of piece that I can instantiate like so:</p>
  
  <pre><code>var pieceOne = new Pawn();
  </code></pre>
  
  <p>The Pawn() should have all the fields and methods of Piece but have its own method for movement, and additional fields (such as whether or not it has moved yet, as this doesn't matter for most pieces). Here's my current Piece class:</p>
  
  <pre><code>//This object specifies basic information about pieces.
  "use strict";
  function Piece(color, type, captured, hasMoved) {    
      this.color = color;
      this.type = type;
      this.captured = captured;
      this.hasMoved = hasMoved;
      this.image = color + "_" + type + ".svg";
  }
  Piece.prototype.getImage = function getImage(){
      return this.image;
  }
  Piece.prototype.isCaptured = function isCaptured(){
      return this.captured;
  };
  </code></pre>
  
  <p>I know if I am going to make a subclass for every kind of piece that I'd probably eliminate the "type" field, but how could I make a Pawn subclass? Something like this?</p>
  
  <pre><code>function Pawn() = new Piece(color, captured, hasMoved);
  Pawn.prototype.getLegalMoves = function getLegalMoves(){
      //return legal moves
  }
  var pieceOne = new Pawn("black", false, false);
  </code></pre>