JSFiddle - React, Tailwind, and code Playground
by blesh
JavaScript
//Multiple inheritance hackery.
console.clear();
function Spider() {
this.crawls = true;
}
function Man() {
this.walks = true;
}
function SpiderMan() {
inherit(this, Spider);
inherit(this, Man);
this.superhero = true;
}
function inherit(obj, Type) {
var sub = obj.__proto__;
while(sub.__proto__.__proto__) {
sub = sub.__proto__;
}
sub.__proto__ = new Type();
}
//SpiderMan.prototype = new Man();
//SpiderMan.prototype.__proto__ = new Spider();
var spidey = new SpiderMan();
var man = new Man();
var spider = new Spider();
//spidey.__proto__.__proto__.__proto__ = new Spider();
function test(name, spidey) {
console.log(name + ' =============');
console.log('instanceof Man', spidey instanceof Man);
console.log('instanceof Spider', spidey instanceof Spider);
console.log('instanceof SpiderMan', spidey instanceof SpiderMan);
console.log(spidey);
}
test('SpiderMan', spidey);
test('man', man);
test('spider', spider);