Why is the function using the "this.property"?


//I ran the code with "//" in front of the this.age, and it still worked. then i tried accessing the "this.age", but it wouldnt let me. pls tell me why the function uses the "this" for its properties
function Cat(age, color) {
this.age = age;
this.color = color;
var orangeTabby = Cat(3,"gold");//setting its properties with paramet
var blackCat = Cat(4,"black");
//orangeTabby.age = 5;

// make a Dog constructor here
function Dog(messiness,ugliness){
this.messiness = messiness;
this.ugliness = ugliness;


When a funcition uses the THIS Keyword it is refering to its properties/arguments...

So lets take for example this:

var argOne = 32
var argTwo = "Some String"
function thisPractive(argOne, argTwo){
  this.argOne = argOne
  this.argTwo = argTwo

Now here whats happening is that this.argOne is refering to the argOne from the Function. And its setting it equal to the global variable that the function has acess too. Im sure now you can implement this concept to your problem. If not reply saying so! Hope this helped!