Summary
In this chapter, we explored different ways of creating objects. We started recalling the basic ways to create objects in JavaScript and then discussed how some design patterns can help us to create more effective code. We have seen how to create singletons and warned about their abuse. Then we analyzed the factory pattern and its variant abstract factory pattern-both allows us to delegate to a specialized object (the factory) the task of creating objects belonging to a specific category. The builder pattern can be useful when creating some kind of objects is a complex process that consists of many steps. In this case, we use a special object (the director) that uses other objects (the builders) to actually create the object. Finally, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access