Chapter 6. Object-orientation with prototypes

In this chapter we discuss

  • Using functions as constructors
  • Exploring prototypes
  • Extending objects with prototypes
  • Avoiding common gotchas
  • Building classes with inheritance

Now that we’ve learned how functions are first-class objects in JavaScript, and how closures make them incredibly versatile and useful, we’re ready to tackle another important aspect of functions: function prototypes.

Those already somewhat familiar with JavaScript prototypes might think of them as being closely related to objects, but once again it’s all about functions. Prototypes are a convenient way to define types of objects, but they’re actually a feature of functions.

Prototypes are used throughout JavaScript as ...

Get Secrets of the JavaScript Ninja now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.