O'Reilly logo

The Principles of Object-Oriented JavaScript by Nicholas C. Zakas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. The advantage ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required