Methods


#1

var bob = new Object();
bob.age = 17;
// this time we have added a method, setAge
bob.setAge = function (newAge){
bob.age = newAge;
};
bob.setAge(56);
bob.getYearOfBirth = function () {
return 2014 - bob.age;
};
console.log(bob.getYearOfBirth());

I cann't understand how bob.getYearOfBirth function get bob's age ?


#2

Which lesson is this? A link would be great, thanks.


#3

https://www.codecademy.com/en/courses/spencer-sandbox/2/3


#4

bob is a defined object with a defined property, age which is bound to the object. bob.age is the value. Note that the variable is bob.age, not just age.