You are previewing Secrets of the JavaScript Ninja.

Secrets of the JavaScript Ninja

Cover of Secrets of the JavaScript Ninja by John Resig and Bear Bibeault Published by Manning Publications
O'Reilly logo

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

The best content for your career. Discover unlimited learning on demand for around $1/day.