classy-classical
Classical inheritance in three JavaScript functions, without sacrificing personal preference.
Installation
npm install classy-classical
Functions
Only three functions are needed for inheritance.
classyClassical.extending(class, superClass)
Rename of util.inherits, used for extending classes. In the following example, RedCar will have the drive function and would return the color 'red'.
var classyClassical = ; { thispreOwned = preOwned;} Carprototype{ return 'Broom broom!';} Carprototype{ return 'unknown';} { classyClassicalpreOwned;} classyClassical; RedCarprototype{ return 'red';}
classyClassical.implementing(class, implementedFunctionNames)
The implementing function is used for checking that functions have been implemented. In the following example, an Error will be thrown as the function name 'isAlive' has not been implemented! On the other hand, no error would be thrown if the function had been implemented.
var classyClassical = ;var animal = 'isAlive' 'walk' ; {}; Catprototype{ console;} classyClassical;
classyClassical.super(instance, superClass[, superFunctionName])
(superFunctionName may be ommitted if the super constructor is to be called)
The super function can be used to call a super function of a class. In the following example, 'unknown' would be returned if getColor were to be called.
var classyClassical = ; { thispreOwned = preOwned;} Planeprototype{ return 'Whoosh whoosh!';} Planeprototype{ return 'unknown';} { classyClassicalpreOwned;} classyClassical; RedPlaneprototype{ return classyClassical;}