JSFiddle - React, Tailwind, and code Playground

by David Buzatto

JavaScript

function Node( desc ) {
    this.desc = desc;
    this.doNodeThing = function() {
        console.log( "noding for " + this.desc );
    }
}
        
function FooNode( desc ) {
    this.desc = desc;
    this.doFooNodeThing = function() {
        console.log( "foo noding for " + this.desc );
    }
}
    
function BarNode( desc ) {
    this.desc = desc;
    this.doBarNodeThing = function() {
        console.log( "bar noding for " + this.desc );
    }
}

function inherit( obj, superObj ) {
    
    for ( var x in superObj ) {
        if ( typeof superObj[x] == "function" ) {
            obj[x] = superObj[x];
        }
    }
}
        
var n1 = new Node( "tree node" );
n1.doNodeThing();

var n2 = new Node( "folder node" );
n2.doNodeThing();

inherit( n1, new BarNode() );
n1.doBarNodeThing();
//n2.doBarNodeThing();

inherit( n1, new FooNode() );
n1.doBarNodeThing();
n1.doFooNodeThing();
//n2.doFooNodeThing();