Social Icons

Pages

Thursday, December 1, 2016

Introduction to Objects I 20/33

The Object Constructor
We mentioned the term constructor back in section one, when we talked about making an object using the keyword new. A constructoris a way to create an object.
When we write bob = new Object( ); we are using a built-in constructor called Object. This constructor is already defined by the JavaScript language and just makes an object with no properties or methods.
This means we have to add our properties one at a time, just like we've been doing. To review, we've created bob using the constructor and defined the name property for you.


Instructions
Finish making bob by defining the ageproperty and setting it equal to 20
                                                        // here we make bob using the Object constructor
                                                           var bob = new Object();
                                                           bob.name = "Bob Smith";
                                                           bob.age = 20;
                                                       // add bob's age here and set it equal to 20

No comments:

Post a Comment