title: Javascript inheriting properties and methods from a class?
body: <p>I'm trying to make a hangman game that uses the canvas to draw the gallow and the man when a letter is picked wrong. I have built a 'Part' class which contains important properties and methods for drawing the parts. But, for drawing body parts, every line is going to be started on the same x-coordinates. So, I attempted to make a 'BodyPart' constructor which is a child of the Part constructor that keeps the same x-coordinates for each BodyPart. But, when I call the 'draw' method on the body parts, it doesn't work. Here is my code:</p>
  
  <pre><code>function Part(x,y, diffFromCenter, y2) {
      this.x = x;
      this.y = y;
      this.x2 = this.x + diffFromCenter;
      this.y2 = y2;
      this.draw = function() {
          context.beginPath();
          context.lineWidth = 3;
          context.moveTo(this.x, this.y);
          context.lineTo(this.x2, this.y2);
          context.stroke();
      };
  }
  
  function BodyPart(y,diffFromCenter,y2) {
      this.x = canvas.width/2;
  }
  
  BodyPart.prototype = new Part();
  
  var torso = new BodyPart(50,0,100);
  var leftArm = new BodyPart(50,-25,75);
  var rightArm = new BodyPart(50,25,75);
  var leftLeg = new BodyPart(100,-25,130);
  var rightLeg = new BodyPart(100,25,130);
  var head = {
      x: canvas.width/2,
      y: 35,
      radius: 15,
      draw: function() {
          context.beginPath();
          context.lineWidth = 3;
          context.arc(this.x, this.y, this.radius, 0, 2*Math.PI);
          context.stroke();
      }
  };
  
  var body = [head, torso, leftArm, rightArm, leftLeg, rightLeg];
  
  for (var i = 0; i &lt; body.length; i++) {
      body[i].draw();
  }
  </code></pre>
  
  <p>I have the 'head' as in its own object since it is an arc. I just don't see why the properties and methods from 'Part' aren't being inherited by 'BodyPart'. The for loop draws out the objects.</p>
  
  <p>To access the canvas, I did the following:</p>
  
  <pre><code>var canvas = document.getElementById("canvas");
  var context = canvas.getContext("2d");
  </code></pre>