JSFiddle - React, Tailwind, and code Playground

by blesh

JavaScript

//multi inherit
function multiInherit() {
    var ctor = arguments[0],
        types = [].splice.call(arguments, 1),
        i, tail = getProtoTail(ctor);

    for (i = 0; i < types.length; i++) {
        (function (type) {
            function Container() {}
            Container.prototype = new type();
            tail.prototype = new Container();
            tail = getProtoTail(type);
        }(types[i]));
    }
    
    ctor.prototype = new tail();
    return ctor;
}

function getProtoTail(ctor) {
    var proto = ctor.prototype;
    while (proto.constructor && proto.constructor.prototype) {
        proto = proto.constructor.prototype;
    }
    return proto;
};

function Spider() {
    this.crawls = true;
}

function Man() {
    this.walks = true;
}

var SpiderMan = multiInherit(function () {

}, Spider, Man);

var spidey = new SpiderMan();

console.log(spidey instanceof Man);
console.log(spidey instanceof Spider);
console.log(spidey instanceof SpiderMan);