Lazy inheritance

Lazy inheritance is a design pattern used in JavaScript computer programming.

It designates a postponed linking of an object with its prototype (class) until it is needed. If used properly, such approach may increase efficiency, simplicity and flexibility of OOP-based code written using JavaScript.

Since lazy inheritance called only once at the moment of first object instance creation, it seems logical to combine process of class prototype creation with resolving necessary dependencies of that class.

The instances of objects in lazy inheritance are created in "mixed" mode — on first invocation, a factory is used to modify class prototype which is later is used for subsequent object instances creation. In other words, the process of prototype construction also allows loading scripts (if ones were not loaded before) which particular class depends on.

Such approach to inheritance support has the following benefits:

See also

Implementation

This article is issued from Wikipedia - version of the 3/1/2013. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.