But this approach of adding in properties one at a time for every object is tedious! Instead of always using the boring Object
constructor, we can make our own constructors.
This way we can set the properties for an object right when it is created. So instead of using the Object
constructor which is empty and has no properties, we can make our own constructors which
have properties.
To see how this works, look at ourPerson
constructor in lines 1–4. This constructor is used to make Person
objects. Notice
it uses the keywordthis
to define the name
and age
properties
and set them equal to the parameters given.