National Pizza Magistrate

    allex_inheritlowlevellib

    3.0.1 • Public • Published

    inherit

    This is a simple lib that exports just two functions:

    ##inherit A well known JavaScript inheritance pattern. Expects two parameters:

    • First one is the child "class"
    • Second one is the parent "class"

    It will create the prototype of the child "class" according to the prototype of the parent "class".

    ##inheritMethods This function expects 2+N parameters:

    • First one is the child "class"
    • Second one is the parent "class"
    • 2+1st is the name of the first method to be copied from the parent "class" prototype to the child "class" prototype
    • and so forth

    Useful for mixin situations (when "implementing interfaces").

    ##Installation

    npm install allex_inheritlowlevellib

    ##Usage

    var inheritlib = require('allex_inheritlowlevellib'),
      inherit = inheritlib.inherit,
      inheritMethods = inheritlib.inheritMethods;
    
    function A () {
      this.classname = 'A';
    }
    A.prototype.print = function () {
      console.log(this);
    };
    
    function B () {
      A.call(this);
      this.classname = 'B';
    }
    inherit(B, A);
    
    var b = new B();
    b.print();
    
    function C () {
    }
    inheritMethods(C, A, 'print');
    
    var c = new C();
    c.print();

    Install

    npm i allex_inheritlowlevellib

    DownloadsWeekly Downloads

    15

    Version

    3.0.1

    License

    ISC

    Last publish

    Collaborators

    • andrija-hers
    • luka111