Introduction

Creating and extending similar objects has always been possible with JavaScript's prototypical inheritance model. By using the new operator and adding prototype properties, we can create structures that behave like classes.

ECMAScript 2015 introduced class syntax as a friendlier way to work with prototypical inheritance. It has been argued that this syntactic sugar is not worth the overhead of having two ways to implement OOP structures. However, I would argue that class provides a more concise way of expressing the same idea, and is a net benefit. As we'll see in this chapter and the next, the class syntax makes it easier to express sophisticated OOP relationships.

Get ECMAScript Cookbook 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.