...

/

Inheriting from a Class: Default Constructors and Legacy Classes

Inheriting from a Class: Default Constructors and Legacy Classes

Learn about the default constructors and legacy classes in inheritance.

Using default constructors

Recall that if you do not write a constructor, JavaScript provides a default constructor for the class. The same rule applies to derived classes, with one bonus: the default constructor automatically calls super to pass any arguments to the base class. This feature is nice and removes the need to write silly constructors that do not do anything except pass data to the base class. Once you get used to it, you may wish languages like Java and C# had this feature.

Default constructor in action

Let’s extend an AwesomePerson ...