How it works...

This recipe differs from the previous simple extension example. By implementing a constructor on InactiveRocket, we are able to pass a different set of arguments. The lastFlown property is unique to InactiveRocket. Thus, we see that property on instances of InactiveRocket, but not on instances of Rocket.

You'll notice that the super method is called in the constructor of InactiveRocket. This manually executes the Rocket constructor for the current instance. That is why the name property is also attached. If we did not execute super, then the Rocket constructor would not have been called.

In this way, we've kept the properties from the parent class Rocket as well as adding an additional property to the InactiveRocket child ...

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.