JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://amatiasq.com/fiddle-console.js"></script>
JavaScript
function $new() {
var obj = Object.create(this);
obj.init.apply(obj, arguments);
return obj;
}
function $extends(base, sub) {
var obj = Object.create(base);
for (var k in sub) { obj[k] = sub[k] };
obj.new = $new;
if (base) {
obj.$super = function() {
return base.init.apply(this, arguments);
};
for (var k in base) if (typeof base[k] == "function") (function(k){
obj["$super_"+k] = function() {
return base[k].apply(this, arguments);
};
})(k);
}
obj.super = base;
return obj;
}
var MyType = $extends(null, {
init: function() {
this.value = "Works!";
},
foo: function() {
return "bar";
}
});
var SubType = $extends(MyType, {
init: function() {
this.$super();
},
fooey: function() {
return this.$super_foo()+"ey";
}
});
var instance = SubType.new();
console.log(instance.value);
console.log(instance.foo());
console.log(instance.fooey());