Object.extend, an example of inheritance
Tuesday, September 2nd, 2008Updated: my previous attempt to simulate inheritance in javascript using Prototype.extend did not work as I expected so I removed the example I had written.
Inheritance can be defined in several ways. The definition of inheritance I will use in the following example is: A child class inherits from a parent class if all methods of parent are available to the child and the child methods override the parent’s ones. The child methods which are not defined on the parent must of course be available on the child object.
And now let’s define a simple class which will act as a child:
To use our subclass, we will run:
Please observe that the parent constructor is totally ignored by this inheritance simulation