What actually the statement want to tell


#1

// here we define our method using "this", before we even introduce bob
var setAge = function (newAge) {
this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
bob.setAge = setAge; /_/ What does this statement is doing??_

/* I understand the concept of method + function and keyword "this".

So if i need to update any information, i would just call like this

bob.setAge(30);

But yes i must be missing some concept of

bob.setAge=setAge;

So please help me in understanding the above code.

Thank You


#2

bob.setAge = setAge

This means that everytime we call setAge from the Bob object it is going to call the function(newAge) since we declared it in the beginning.

The "bob.setAge" can be anything, it can something like this " bob.nowLetMeSetYourAgeForYou = setAge ".

The setAge is a function.