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, ...

Get Mastering JavaScript Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.