JSFiddle - React, Tailwind, and code Playground
JavaScript
function clazz(_class, _super) {
var _prototype = Object.create((_super || function() {}).prototype);
var _deps = Array.isArray(_class) ? _class : [_class]; _class = _deps.pop();
_deps.push(_super);
_prototype.constructor = _class.apply(_prototype, _deps) || _prototype.constructor;
_prototype.constructor.prototype = _prototype;
return _prototype.constructor;
}
var Alpha, Beta, alpha, beta;
Alpha = clazz(['DepA', function(_depA, _super) { // Class closure with dependency injection
var _getA = function(a) { return _depA+'.'+a; }; // private static method which depends on _depA
return function Alpha(a) { // a = private instance variable
this.getA = _getA.bind(this, a); // instance method calling on private static method
};
}]);
alpha = new Alpha('a');
console.log('alpha.getA()', alpha.getA()); // a
Beta = clazz(function(_super) { // subclass closure
var _getB = function(b) { return b; }; // private static method
this.say = function(msg) { return msg; }; // public static method
return function Beta(a, b) {
var z = a + b; // private instance variables
var get = function(obj) { return obj; }; // private instance method
_super.apply(this, arguments);
this.getB = _getB.bind(this, b); // public instance method calling on private static method
this.getZ = get.bind(this, z); // public instance method calling on private instance method
};
}, Alpha); // extend
beta = new Beta('A', 'B');
console.log('beta.getA()', beta.getA()); // A
console.log('beta.getB()', beta.getB()); // B
console.log('beta.getZ()', beta.getZ()); // AB
console.log('beta.say("hello")', beta.say("hello")); // hello
console.log('alpha instanceof Alpha', alpha instanceof Alpha); // true
console.log('beta instanceof Alpha', beta instanceof Alpha); // true
console.log('beta instanceof Beta', beta instanceof Beta); // true