JSFiddle - React, Tailwind, and code Playground

by lbstr

JavaScript

var Human = {
    isAlive: true,
    say: function(what){
        alert(what + '!');
    },
    die: function(){
        this.isAlive = false;
    }
};

function HumanMaker(f) {
    var h = Human;
    h.__proto__ = f.__proto__;
    f.__proto__ = h;
    return f;
}

//These will inherit from it:
var ninja = HumanMaker(function() {
    alert("I'm a ninja!");
});
var samurai = HumanMaker(function(){
    alert("I'm a samurai!");
});

//Now, how can I make ninja and samurai behave like this:
ninja(); //I'm a ninja!
samurai(); //I'm a samurai!
ninja.say('Hello'); //Hello!


ninja.die();
alert(ninja.isAlive == false);

alert(samurai.isAlive == true);