JSFiddle - React, Tailwind, and code Playground

by fkling

JavaScript

function BaseObject(name){
    this.name = name;

    this.sayWhoAmI = function(){
        console.log(this.name + ' is a Derivation1 : ' + (this instanceof Derivation1));
        console.log(this.name + ' is a Derivation2 : ' + (this instanceof Derivation2));
        console.log(this.name + ' is a BaseObject : ' + (this instanceof BaseObject));
    };
}
function Derivation1(){
    BaseObject.apply(this, ['first derivation']);
}
Derivation1.prototype = Object.create(BaseObject.prototype);
Derivation1.prototype.constructor = Derivation1;

function Derivation2(){
    BaseObject.apply(this, ['second derivation']);
}
Derivation2.prototype = Object.create(BaseObject.prototype);
Derivation2.prototype.constructor = Derivation2;

var first = new Derivation1();
var second = new Derivation2();
first.sayWhoAmI();