Explanation
Let's look at the code in chunks
Constructor Function
This looks similar to our Person()
function, but with a few differences. 1. Two new properties
isMarried - a boolean that states whether or not the parent is married.
occupation - a string that stores the parent's job.
Person.call()
We need to call on the properties already defined by the
Person
object. It is crucial that you also include the this keyword. That way we can use all these properties.
Prototype
In this bit of code, we create the Parent constructor function based on the Person constructor function. Parent uses Person as a template or prototype.
Job Function
Here, we create a function to primarily output Parent's occupation property. 1. We create the function on the constructor's prototype property.
We use an if/else statement to output either is or are based on Parent's gender pronoun.
Displaying the Results
Here's where we put it all together. 1. We create a new instance of the Parent object. 2. We log data to the console. Functions need to be logged separately because they aren't technically properties.
Last updated