Social Icons

Pages

Thursday, December 1, 2016

Introduction to Objects I 14/33

// here is bob again, with his usual properties
var bob = new Object();
bob.name = "Bob Smith";
bob.age = 20;
// this time we have added a method, setAge
bob.setAge = function (newAge){
  bob.age = newAge;
};
// here we set bob's age to 40
bob.setAge(20);
// bob's feeling old.  Use our method to set bob's age to 20

No comments:

Post a Comment