s-inherit
Node.js
installation for npm i s-inherit --save
Browser
installation for bower i s-inherit --save
An easy way to make inheritance constructors for "ES5".
Inherit
Node util "inherits" gives the mode of inheritance.
var inherit = require('s-inherit');// rewrite constructorinherit(Child, Parent); // the same as util.inherits// make a instancevar instance = new Child();
Make constructor from others
When constructor inheritance, constructor which inherit got a link to super and broken for origin.Thoughts on the re-use base constructor led to the idea - to create a new constructor that inherits but does not overwrite the other (basic / decorating). This results in the creation of necessary construtors on the basis of any previously created and does not prevent their reuse further.
Example:
var inherit = ;// without broken origin constructorvar NewConstructor = inherit;
Note: without changing "Child". (NewConstructor != Child)
usually expects a interface for future class.
{ ...}Interface1prototype = ...;// different interfaces { ...}Interface2prototype = ...;
after that, setting a base functionality.
{ ...}Base1prototype = ...;// different functionality { ...}Base2prototype = ...;
after that, we want set a realization.
{ ...}Foo1prototype = ...;// different realizations { ...}Foo2prototype = ...;
Example usage compilation for constructors
var inherit = ;// create constructor without broken origin constructor and prototypesvar Model1 = inherit;var Model2 = inherit;// or maybe Some thing more complicated// in most cases it really hard to mergevar Model3 = inherit;
Note: But if each of Constructor do not have relation based on inherent and still have the original version. It can be not so hard.
Decorate
Sometimes you need to make a decoration of the model, adding methods and fields for a particular implementation without affecting its inheritance, and without breaking the original class. How can it be.
Example:
var inherit = ;// make new class decorated for existing class of existing decorator and addition sourcevar Decorated = inherit;var instance = 'test' ;instancetop; // => 100 if it not overided from "Foo" constructor
Note: scenery method ignores the prototypes of the classes.
Super
say - "We wanna get a SUPER - and that super must be a unique for each model which we defined"
This is a difficult moment. But I have a proposal for its decision. Since multiple inheritance, the main problem for a unique index transmission, within a single prototype class parent.
ans - "I offer to attend to yourself about how to point out the Super"
Extension expects a special method called "_setSuper" and correctly sends the super of model.
Example:
{ console; thissource4 = 'Foo4';} Foo4prototype = { thisSuperprototype; }; /*------------------------------------------------- WTF ??? it's method to set super by unique name for this Class I think this is a good solution for es6 Since the syntax of classes implementing in ES6 more limits the javascript classes, than expanding their.---------------------------------------------------*/var Super = Symbol;Foo4 { // you can call to super or super prototype by this unique name thisSuper = thisSuper||Parent;};