OOjs/Inheritance

OOjs builds on JavaScript's native prototypal inheritance model, adding mixins and inheritable static properties and methods.

Classes
A class can inherit methods and properties from a parent class. This is done by chaining the child class's prototype, making method and property lookups fall through to the parent's prototype.

First, call the parent's constructor within the child's constructor. This will initialize functionality provided by the parent class.

Second, use  to setup the prototype chain. This will also setup inheritance for inheritable static methods and properties.

When creating a base class, which other classes will inherit from but does not inherit from other classes, use the  method. This will add support for inheritable static methods and properties.

[code example]

Mixins
A class can mixin methods and properties from any number of other classes. This is done by copying methods and properties from the prototype of one class to another. Inheritable static methods and properties are also copied.

Classes are usually written specifically to be mixed into others. It is important to understand that only a class's own prototype properties will be copied when it is mixed into another class, so using  for a mixin will cause inherited properties and methods to not be accessible.

First, call the mixin's constructor within the class's constructor. This will initialize functionality provided by the mixin class.

Second, use  to copy the methods and properties to the class.

Static methods and properties
Some methods and properties are associated with the class rather than an instance of the class. If,  , or   are called on a class, the constructor will have a   property. This property is an object which has a prototype chain, allowing static methods and properties to be inheritable.