The journey to discovering what makes JavaScript a joy to code with starts with its object system. Objects are the foundation for everything you do and everything you will be able to do with the language. Object design is used to make sense of your domain and how all its pieces relate and pass messages to one another. As powerful as the object system is, however, it can be quite stressful to figure out which patterns to use—a task that everyone seems to do slightly differently. We can catalog patterns based on two groups: prototypal and delegation. This part gives you an overview of each pattern and its strengths.
In chapter 2, we start by reviewing JavaScript’s prototype mechanism. Anything meaningful you do with JavaScript requires you to understand how prototype hierarchies work and how properties are resolved by the JavaScript runtime. Prototypal inheritance enables some nice object-oriented techniques to construct objects by using Object APIs, constructor functions, and classes.
Prototypal inheritance may lead to a tight coupling among objects that belong to the same hierarchy, which tends to become brittle over time. Chapter 3 teaches you some techniques to combat this situation. These techniques are compositional in nature, clearly demarcating object links to make your object models a bit more maintainable. In this chapter, you’ll learn about techniques such as OLOO (Objects Linked to Other Objects) and mixins.