Is this considered a Property or Method?


#1

Is bob.setAge on line 9 considered a method, or is it a property that is set equal to the setAge method I made first? If we call on bob.setAge to change his age then that leads me to believe that it is considered a function, or more specifically, a method. I understand the code's functionality. I just want to make sure I understand the terminology correctly.

// 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;
// and down here we just use the method we already made
bob.setAge = setAge;
  
// change bob's age to 50 here
bob.setAge(50)


#2

Yes this right here is a method,


#3

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