title: Javascript object encapsulation that tracks changes
body: <p>Is it possible to create an object container where changes can be tracked</p>
  
  <p>Said object is a complex nested object of data. (compliant with JSON).</p>
  
  <p>The wrapper allows you to get the object, and save changes, without specifically stating what the changes are</p>
  
  <p>Does there exist a design pattern for this kind of encapsulation </p>
  
  <p>Deep cloning is not an option since I'm trying to write a wrapper like this to avoid doing just that.</p>
  
  <p>The solution of serialization should only be considered if there are no other solutions. </p>
  
  <p>An example of use would be</p>
  
  <pre><code>var foo = state.get();
  // change state
  state.update(); // or state.save();
  client.tell(state.recentChange());
  </code></pre>
  
  <p>A jsfiddle snippet might help : <a href="http://jsfiddle.net/Raynos/kzKEp/" rel="nofollow">http://jsfiddle.net/Raynos/kzKEp/</a></p>
  
  <p>It seems like implementing an internal hash to keep track of changes is the best option.</p>
  
  <p>[Edit]</p>
  
  <p>To clarify this is actaully done on node.js on the server. The only thing that changes is that the solution can be specific to the V8 implementation.</p>