Chapter 12Object-oriented Programming in JavaScript

Object-oriented programming (OOP for short) is a style of programming that involves separating the code into objects that have properties and methods. Sound familiar? JavaScript obviously supports objects, as we saw in Chapter 5, so it also supports an object-oriented style of programming. In this chapter, we’ll look at what object-oriented programming is and how to implement it in JavaScript.

In this chapter, we’ll cover the following topics:

  • an introduction to OOP

  • constructor functions

  • prototypes

  • public and private methods

  • inheritance

  • creating objects from objects

  • adding methods to built-in objects

  • mixins

  • chaining functions

  • this and that

  • borrowing methods from prototypes

  • our project―create ...

Get JavaScript: Novice to Ninja 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.