JSFiddle - React, Tailwind, and code Playground

JavaScript

var Person = function (name) {
  this.name = name;
  this.onNameChangedCallbacks = [];
}

Person.prototype.onNameChanged = function(callback) {
  this.onNameChangedCallbacks.push(callback);
}

Person.prototype.setName = function (name) {
  this.name = name;
  this.onNameChangedCallbacks.forEach(function (callback){
    callback(name);
  });
}

var adam = new Person('Adam');

adam.onNameChanged(function(newName) {
  alert('New name is set to: ' + newName);
});

adam.setName('eva');