Learning Echo Core JavaScript

JavaScript's Prototypal Inheritance

JavaScript's "prototype-based inheritance" in which a class is derived from an instance of an object, state and all, rather than from a base class as in object-oriented inheritance.

This is shown in the demo below. The class Alpha contains an array, 'stuff', into which elements are added using the 'addStuff' function. When using two instances of Alpha, the behavior is as expected, each instance adds to it's own copy of 'stuff'

Beta is then created and it's prototype is assigned from Alpha, it's prototypal superclass. Class Beta does inherit the 'addStuff' function but not in the classical object-oriented sense. Rather than each instance of Beta inheriting it's own copy of 'stuff', all instances of Beta access the the same 'stuff' array when invoking 'addStuff'.

More on the Echo site...

More on the prototypal inheritance...