JSFiddle - React, Tailwind, and code Playground
by Skip Wilson
JavaScript
function makeClass() {
return function f(args) {
if(this instanceof f){
if(typeof this.init === "function") {
this.init.apply(this, args);
}
} else {
return new f(arguments);
}
};
}
var BaseClass = makeClass();
BaseClass.prototype.init = function(n){
console.log("baseClass: init:" + n);
}
var SubClass = makeClass();
SubClass.prototype = Object.create(BaseClass.prototype);
SubClass.prototype.init = function(n) {
BaseClass.prototype.init.call(this,n); // calling super();
console.log("subClass: init:" + n);
}
var s = SubClass("subClass");