Answer the following questions and make the tests pass.
-
What is the purpose of a constructor function?
-
What does the
new
keyword do? -
What does the keyword
this
refer to inside of a constructor function? -
What is a
class
? What is aninstance
? -
Create a constructor function for a Person, each person should have a firstName, lastName, favoriteColor and favoriteNumber.
-
Write a method called multiplyFavoriteNumber that takes in a number and returns the product of the number and the Person's favorite number
-
Refactor the following code so that there is no duplication inside the
Child
function.
function Parent(firstName, lastName, favoriteColor, favoriteFood){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteFood = favoriteFood;
}
function Child(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
this.favoriteColor = favoriteColor;
this.favoriteFood = favoriteFood;
}