In the last section, we discussed properties. We can think of properties as variables associated with an object. Similarly, a method is just like a function associated with an object.
Let's look at
bob, our same person object from the last lesson. Instead of just having the properties
age (line 3 & 4),
bob also has a method called
setAge (line 6). As you can probably guess, this method sets
bob's age to whatever argument you give it.
Notice how we define
setAge kind of like we define a property. The big difference is that we put in a function after the equals sign instead of a string or number.
We call a method like a function, but we use
ObjectName.methodName(). Look at line 10 where we use the method to change
bob's age to
40. We did this by calling