Why would you use "this" in the given example?



Everything works out well, I was just wondering why you would use "this" in the given example? Is there someone with an explanation?

var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
rectangle.setHeight = function (newHeight) {
  this.height = newHeight;


Does this refer to something that you want to manipulate?
What is the purpose of the function?
What does the function need to do? What data does it need to access? Where can the function get access to that data?


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