concept subclass in category ext js

appears as: subclasses, subclasses, subclass, subclass
Ext JS in Action, Second Edition

This is an excerpt from Manning's book Ext JS in Action, Second Edition.

Figure 1.6. Commonly used subclasses of Container—FormPanel, TabPanel, FieldContainer, and Toolbar—and the layouts used to compose this UI window. We’ll build this in chapter 6, when you learn about forms.

In this chapter, you’ll learn the basics of extending (subclassing) with Ext JS. You’ll begin by learning how to create subclasses with JavaScript, and you’ll see what it takes to get the job done with the native language tools. This knowledge will give you the foundation to refactor your newly created subclass in order to use the Ext JS class system.

13.1.2. Creating a subclass

You can create a subclass using native JavaScript in several steps. Rather than simply describing them, we’ll walk through the steps together. The next listing shows you how to create PremiumCar, a subclass of the BaseCar class.

Listing 13.2. Creating a subclass the old-school way

To create a subclass you begin by creating a new constructor, which is assigned to the reference PremiumCar . Within this constructor is a call to the constructor method of PremiumCar.superclass; within the scope of the instance of PremiumCar you’re creating (this).

You do this because, unlike other object-oriented languages, JavaScript subclasses don’t natively call their superclass constructor. Calling the superclass constructor gives it a chance to execute and perform any constructor-specific functions that the subclass might need. In this case, the shiftTo method is being added and called in the BaseCar constructor. Not calling the superclass constructor would mean that your subclass wouldn’t get the benefits provided by the base class constructor.