This. question 19/33


As I understand this. is used so that the method is not just limited to one particular object but can be applied to different objects.
In the example in 19/33 (below) I don't understand that. Here this is used BUT it only refers to the object square and it is part of square-so why do we use this here?

var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
// help us define an area method here
square.calcArea= function() {
return this.sideLength * this.sideLength;

var p = square.calcPerimeter();
var a = square.calcArea();

Thank you!


I have this exact question as well. In the previous exercises "this" is accurately described as being used so that a method can be applied to multiple objects and so we don't have to write the same method in each object. Makes sense.

But then immediately after in exercises 18-19 "this" is used inside of objects (rectangle, square). The instructions say:

"Notice we have use the keyword 'this'. 'this' is still a placeholder, but in this scenario, 'this' can only ever refer to 'rectangle' because we defined 'setHeight' to be explicitly part of 'rectangle' by defining it as 'rectangle.setHeight'."

Okay, so then what is the benefit of using 'this' in this exercise? If we defined the method to be specific to the object, then why don't we just write "rectangle.height = newHeight;" like we did in the first exercise (bob.age = newAge;)? Again, what is the benefit or difference in using 'this' in this scenario? It's not explained anywhere. Exercise 19 is the last one in that section. Exercise 20 starts with something new.