JSFiddle - React, Tailwind, and code Playground

JavaScript

function Variable(initVal, onChange)
    {
        this.val = initVal;
        this.onChange = onChange;

        this.GetValue = function()
            {
                return this.val;
            }
            
        this.SetValue = function(value)
            {
                this.val = value;
                this.onChange();
            }
    
    
      }
      
                
                var myVar = new Variable(10, function(){alert("Value changed!");});


alert(myVar.GetValue());
                
myVar.SetValue(12);

alert(myVar.GetValue());