JSFiddle - React, Tailwind, and code Playground

JavaScript

function f() {     
    this.data = "hello world";     
    this.getData = function() {         
        return this.data;     
    }; 
}

function g() {
    this.data = "another message";
}

var a = new f();
alert( a.getData() );

var b = new g();
b.getData = a.getData;
//alert( b.getData() );