Learning Echo Core JavaScript

Using a Shared Prototype

There is a solution to this problem. We can create a new class that has an empty constructor that shares its prototype with the base class. Derivative classes can then be derived from an instance of the empty-constructor-version

This is shown in the demo below. As in prototypal inheritance the class Alpha contains an array, 'stuff', into which elements are added using the 'addStuff' function. Beta and it's subclass Gamma use a 'shared prototype' of their superclass and add an additional array along with the functions, 'addJunk' and 'addCrap' which populate them.

Unlike the previous example which used prototypal inheritance, these class behave more like object-oriented classes in which the functions are inhertied but the member variables are not.

More on the Echo site...

More on JavaScript object-oriented inheritance...