lazy-extendable

Lazy and unobturisve JavaScript inheritance

LazyExtendable

Lazy and unobturisve JavaScript inheritance helper

npm install lazy-extendable

Download and reference via script

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

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().

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

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.

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 {
        sayfunction () {
            var buffer = [];
 
            buffer.push(this._find());
            buffer.push(this._greet());
            buffer.push(this._throwPlate());
 
            return buffer.join(' ');
        },
        _findfunction () {
            return 'Here you are, jerk!';
        },
        _greetfunction () {
            return 'Hello my darling.';
        },
        _throwPlatefunction () {
            return 'Take this!';
        }
    };
});
 
var PoliteWoman = Woman.extend(function (base) {
    return {
        sayfunction () {
            return base._greet();
        }
    };
});

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.

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