  <script src="https://unpkg.com/jquery/dist/jquery.min.js"></script>
  
  <script>
x = {
  aInternal: 10,
  aListener: function(val) {},
  set text(val) {
    this.aInternal = val;
    this.aListener(val);
  },
  get text() {
    return this.aInternal;
  },
  registerListener: function(listener) {
    this.aListener = listener;
  }
}

x.registerListener(function(val) {
  alert("Someone changed the value of x.a to " + val);
});

<script>