13/24 constructors with methods


Replace this line with your code.

In the function of area calculation why are we using this.height and this.width instead of height and width, even in presence of the fact that we already used this.calcPerimeter?I mean,I just want a more simple understanding about usage of .this in custom instructor.


You use this. when you are specific tolking about one atributte or method that belong to that object and not about anybody else.

In the following example this.height, this.width specify the update of height and width respectively of that object that you just past as a parameter.

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

I hope it help you.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.