better-js-class

A convenient way to emulated class and inheritance in Javascript.

class

A convenient way to emulated class and inheritance in Javascript.

Why is this "better"? In the inheritance case, the super function can be called without explicitly referring to the parent class. One can just write:

this.parent.methodName.call(this, args);

Example

var Class = require('better-js-class');
 
var A = Class({
    _initfunction() {
        this._bar = 'bar';
    },
 
    foofunction() {
        console.log('foo ' + this._bar);
    }
});
 
var B = Class(A, {
    _initfunction() {
        this.parent._init.call(this);
    },
 
    kazfunction() {
        console.log('kaz ' + this._bar);
    }
});
 
var a = new B();
a.foo();
a.kaz();

The constructor function's name is conventioned to be "_init".