title: Is there a way to trigger a callback when an object creates or modifies a key/value in JavaScript?
body: <p>I am trying to figure out how to create an object in JavaScript that will trigger events on creation and change of arbitrary key/values. Here is some psuedocode:</p>
  
  <pre><code>var User = function () {
      var user = {};
  
      function keyAdded() { /* trigger an event */ }
      function keyChanged() { /* trigger an event */ }
  
      return user;
  },
  u = new User();
  
  u.test = "testing"; // I want this to trigger an event (keyAdded)
  u.test = "more testing"; // I want this to trigger another event (keyChanged)
  </code></pre>
  
  <p>I am stuck. Any ideas?</p>