Social Icons

Pages

Thursday, December 1, 2016

Introduction to Objects I 22/33

Try it Out!
Let's look at another example and practice coding constructors. Here we have made aCat constructor for you, with age and colorproperties.
Why is this Cat constructor so cool? It means if we have many cats and wanted to create an object for each cat, we could just use this constructor with the properties already defined.
This is much better than using the Objectconstructor which just gives us an empty object and needs us to define every property and value for each cat object we would create.

Instructions
Finish the Dog constructor we have started online 7. You can include whatever parameters and properties you want (age, name, breed, whatever you can think of!) Use the Catconstructor as an example.
function Cat(age, color) {
  this.age = age;
  this.color = color;
}
// make a Dog constructor here
function Dog(age, color) {
  this.age = age;
  this.color = color;
}

No comments:

Post a Comment