Chapter 4. Constructors and Prototypes
You might be able to get pretty far in JavaScript without understanding constructors and prototypes, but you wonât truly appreciate the language without a good grasp of them. Because JavaScript lacks classes, it turns to constructors and prototypes to bring a similar order to objects. But just because some of the patterns resemble classes doesnât mean they behave the same way. In this chapter, youâll explore constructors and prototypes in detail to see how JavaScript uses them to create objects.
Constructors
A constructor is simply a function that is used with new
to create an object. Up to this point, youâve seen several of the built-in JavaScript constructors, such as Object
, Array
, and Function ...
Get The Principles of Object-Oriented JavaScript 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.