JSFiddle - React, Tailwind, and code Playground
by jfriend00
HTML
<div id="result"></div>
CSS
#result {
font-family: "Courier New";
font-size: 14px;
}
JavaScript
function log(str) {
var div = document.createElement("div");
div.innerHTML = str;
document.getElementById("result").appendChild(div);
}
function foo() {
var a = 1;
this.getA = function () { return a; };
}
function extend(parent, fn) {
var newConstructor = function() {
fn.call(this);
}
newConstructor.prototype = new parent();
return newConstructor;
}
var bar = extend(foo, function () {
var b = 2;
this.getB = function () { return b; };
});
var obj = new bar();
log(obj.getA()); //1
log(obj.getB()); //2
log(obj instanceof bar); //true
log(obj instanceof foo); //true