JSFiddle - React, Tailwind, and code Playground

by Neal

HTML

<div id='button'>[TESTING BUTTON]</div>

<div id='results'></div>

JavaScript

// A simple Javascript Object 
var object = new (function(){
    this.text = 'hello';

    this.setText = function(msg){
         this.text = msg
         //on change event
             console.log(this.text);
        document.getElementById("results").innerHTML += this.text;
        
    }
})();

// Imagine a button in the DOM, and if it's clicked the object value will change
document.getElementById("button").onclick = function(){
   object.setText('New Text');
}