- Object Constructors
- Higher Order Functions
- Accessing Prototypes
Object Oriented Programming has been around for a long time because it works. Organizing your code in an Object Oriented manner allows for modularity and extensibility. As projects become larger, this level of organization / architecture becomes extremely important.
Leveraging Higher Order Functions is also an important skill. Re-writing or copy/pasting the same or similar code is inefficient and can end up costing you time in the long run (especially if that duplicated code needs to change). Being able to leverage code you've already written through other functions/methods will help you stay more organized and your code more maintainable.
Define several constructors and prototype methods.
- Introduction to Object-Oriented JavaScript
- 3 ways to define a JavaScript class
- Eloquent Javascript Ch8 - Object-Oriented Programming
- Define a constructor for the following object. Add parameters to the constructor for the given properties and add them as instance variables.
- FoodItem
- string name
- number calories
- boolean vegan
- boolean glutenFree
- boolean citrusFree
- FoodItem
- Define a
stringify
method on the constructor's prototype. It should return a string description of the food including its name, calories, and dietary information, formatted as you choose.stringify
should not have any side effects. Instantiate three different FoodItems and store each in a separate variable. Callstringify
on each instance and print the result to the console.
- Define constructors for the following objects. Add parameters to the constructor for the given properties and add them as instance variables.
- Drink
- string name
- string description
- number price
- Array of FoodItem ingredients
- Plate
- string name
- string description
- number price
- Array of FoodItem ingredients
- Order
- Array of Plate plates
- Menu
- Array of Plate plates
- Restaurant
- string name
- string description
- Menu menu
- Customer
- string dietaryPreference
- Drink
- Define a
stringify
method on each constructor's prototype. This method should return a string representation of the object, formatted as you choose. stringify should not have any side effects. You may want to reuse thestringify
method of the contained objects. (e.g. the Menu object should callstringify
on each of its plates to reuse that functionality instead of having to duplicate the code for each plate). - Add the following methods to the Plate object to determine if all the food items within it fit a specific dietary restriction.
- boolean isVegan
- boolean isGlutenFree
- boolean isCitrusFree
- Instantiate a Burrito Plate, a Guacamole Plate, and a Margarita Drink.
- Instantiate a Menu that contains each of the instantiated Plates and Drinks.
- Instantiate a Restaurant that contains the instantiated Menu.
- Call the Restaurant's stringify method to have it print out all its information.