JSFiddle - React, Tailwind, and code Playground
JavaScript
var MyFoo = {
_instance : null,
Instance : function(){
if(this._instance == null)
{
this._instance = new this.Object();
}
return this._instance;
},
Object : function()
{
this.name = 'not robert';
}
}
function MyBar (){
this.setMyFoosName = function ( name ) {
MyFoo.Instance().name = name;
}
}
Bar = new MyBar()
Bar.setMyFoosName('Robert');
//Test
alert(MyFoo.Instance().name)