Call the constructor from base class | |
A constructor assigns all properties and methods using the this keyword. | |
You can make the constructor of BaseClass into a method of SubClass and call it. | |
After the calling, subClass receives the properties and methods defined in BaseClass's constructor. | |
In the following code, the 'newMethod' is assigned to BaseClass. | |
Then, the 'newMethod' is called, passing the color argument from the SubClass constructor. | |
The final line of code deletes the reference to BaseClass so that it cannot be called later on. | |
|