Question


#1

The code work's but I wana know why when I replace this roaad "susan.setAge(35);" with "setAge"(the name of the function won't work?). I mean we still call the function which is equal with "susan.setage"

Replace this line with your code. 
// 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;
  
// make susan here, and first give her an age of 25
var susan = {};
susan.age = 25;
susan.setAge = setAge;


// here, update Susan's age to 35 using the method
susan.setAge(35);
console.log(susan.age);


#2

I'm not 100% sure I understand your question but setAge is a general function. You need to specify which object you are referring to when you want to change their setAge.


#3

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