JSFiddle - React, Tailwind, and code Playground
by michaelghayes
HTML
Child get: <span id="child"></span></br>
Parent get: <span id="parent"></span>
JavaScript
Function.prototype.inherit = function(parentClass) {
var newPrototype = Object.create(Object.create(parentClass.prototype));
for(key in this.prototype){
newPrototype[key] = this.prototype[key];
}
this.prototype = newPrototype;
this.prototype.constructor = this;
this.prototype.parentClass = parentClass;
this.prototype.initParent = function(args) {
var proto = Object.getPrototypeOf(Object.getPrototypeOf(this))
this.parentClass.apply(proto, args);
}
this.prototype.uber = function() {
return Object.getPrototypeOf(Object.getPrototypeOf(this));
}
}
function BaseClass(n) {
this.value = n;
}
BaseClass.prototype.get = function() {
return this.value;
}
function Model(n) {
this.initParent(arguments)
this.test = n*2;
}
Model.inherit(BaseClass);
Model.prototype.get = function() {
return this.test;
}
m = new Model(1);
$("#child").html(m.get());
$("#parent").html(m.uber().get());