JSFiddle - React, Tailwind, and code Playground

JavaScript

var observableMethods = function() {
    
    this.observers = [];
    
    this.observe = function(observer) {
        this.observers.push(observer);
    };
    
    this.notify = function(data) {
        for (var i=0, ilen=this.observers.length; i<ilen; i++) {
            this.observers[i](data);
        }
    }
};
    
var person = {
    name: 'Steve',
    setName: function(name) {
        var oldName = this.name;
        this.name = name;
        this.notify({oldName: oldName, newName: this.name});
    }
};

observableMethods.call(person);
person.observe(function(data) {
    alert(data.oldName + ' was renamed to ' + data.newName);
});

person.setName('Sarah');