JSFiddle - React, Tailwind, and code Playground
JavaScript
function Person(name) {
this.name = name;
this.someOtherProperty = null;
this.watch = function(cb)
{
var self = this;
Object.observe(this, function(changes){
for(var i = 0; i < changes.length; i++)
{
if(changes[i].name == "name")
{
console.log(changes);
self.someOtherProperty = changes[i].object.name;
console.log("Property Changed");
cb();
}
}
});
}
}
$(function () {
var p = new Person("Alice");
p.watch(function(){
$("#output").text("Output: "+ p.someOtherProperty);
});
p.name = "Bob";
console.log("Output");
});