How it works...

Just like the instance methods, static methods defined on the child override those on the parent class. We created the Rocket class with a static method that locates a Rocket instance based on its name. We also created an InactiveRocket class with its own find method that searches in a different map. Because the InactiveRocket class calls super in its constructor, instances of both classes are added to the map used by the Rocket class's find method. While only instances of InactiveRocket are added to the map used in that class's find method.

When we call find on the Rocket class we are able to retrieve instances of both classes. You'll notice that we are unable to locate instances of the base class using the InactiveRocket ...

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.