How it works...

Adding methods to the body of a class definition is the same as attaching properties to the prototype of a function, with functions as their values. This means that those properties are added as properties to the instance of the new object. When these methods are called, the context (the value of this) is the current instance.

This is similar to the Defining function properties as methods on a plain object recipe in Chapter 6, Plain Objects. In that recipe, we overrode methods by direct assignment. By contrast, in this recipe, we are doing this on the prototype. That means that this override applies to every instance of the InactiveRocket subclass.

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.