extend-interface

1.0.1 • Public • Published

extend-interface

An ultra-lightweight prototypal inheritance mechanism built into the class definition itself.

Usage

    const extendClass = require('extend-interface');

    let MyClass = function(){ }

    MyClass.prototype.output = function(){
        console.log(this.value())
    };
    MyClass.prototype.value = function(){
        throw new Error('No value() implementation')
    };
    MyClass.extend = function(cls, cns){
        var cons = cns || function(){
            MyClass.apply(this, arguments);
            return this;
        };
        return extendClass(cls, cons, MyClass);
    };

then, in another class, you can implement:

    const extendClass = require('extend-interface');

    let SubClass = MyClass.extend({
        value : function(){
            return 'awesome';
        }
    })
    let subClassInstance = new SubClass();

Readme

Keywords

none

Package Sidebar

Install

npm i extend-interface

Weekly Downloads

8

Version

1.0.1

License

none

Unpacked Size

5.95 kB

Total Files

6

Last publish

Collaborators

  • khrome