lazy-extendable

Lazy and unobturisve JavaScript inheritance

npm install lazy-extendable
9 downloads in the last month

LazyExtendable Build Status

Lazy and unobturisve JavaScript inheritance helper

Installation

Node

npm install lazy-extendable

Browser

Download and reference via script

<script src="lazy-extendable.js"></script>

Why another inheritance framework?

Proper naming

It's not a Klass, and not even Class. It's just JavaScript inheritance helper and it's called LazyExtendable. If you want to create new extendable type you call new LazyExtendable() or LazyExtendable.create(), not .extend. Want to extend your type? Use YourType.extend().

Unobtrusiveness

It doesn't add any own properties to prototype. Want add base or super property to you type? Now you can.

Lazyness

Have a huge type hierarchy and it's all built every time, even when unneeded? Forget it, now certain types will be built only if you use them.

Advanced overriding

It's not necessary to change base types, just override method you need and call any base method you want.

var Woman = new LazyExtendable(function () {
    return {
        say: function () {
            var buffer = [];

            buffer.push(this._find());
            buffer.push(this._greet());
            buffer.push(this._throwPlate());

            return buffer.join(' ');
        },
        _find: function () {
            return 'Here you are, jerk!';
        },
        _greet: function () {
            return 'Hello my darling.';
        },
        _throwPlate: function () {
            return 'Take this!';
        }
    };
});

var PoliteWoman = Woman.extend(function (base) {
    return {
        say: function () {
            return base._greet();
        }
    };
});

Naming again

Now you can name base instance as you want. Like Java? Call base methods via super. Like C#? Call via base. Like LOTR? Call it via gandalfTheGrey.

Advanced IDE autocompletion

You can specify exact type of base type with annotations your IDE understand and get better autocompletion behavior.

npm loves you