24. Constructors with Methods


Right, so I'm a bit puzzled with the line var area = rex.calcArea(); .
Why isn't the area called up like this: var area = rectangle.calcArea() ?
Because aren't we getting the area straight from the Rectangle? Or can we do both ways?


function Rectangle(height, width) {
  this.height = height;
  this.width = width;
  this.calcArea = function() {
      return this.height * this.width;
  this.calcPerimeter = function() {
      return 2 * this.height + this.width * 2;

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();



Soo... when you made rex, you said it was a new Rectangle, so Rectangle gave rex all of Rectangle's functions. So, although Rectangle still has the function calcArea(), rex has it as well, and it only makes sense when you call it from rex.


Thanks pal (Thumbs up emoji)