title: Updating Custom Object Properties in JavaScript
body: <p>I'm tired of looping through an object literal to get its length for one reason or another. I want to define a <code>length</code> property onto <code>Object.prototype</code>, I can set the initial length, but I don't know how to update it when the object is modified?</p>
  
  <pre><code>var obj = {a:1, b:2, c:3};
  Object.defineProperty(Object.prototype, 'length', {value: 0});
  
  //  obj.length === 0;
  
  obj.d = 4;
  
  //  obj === {a:1, b:2, c:3, d:4};
  //  obj.length === 0;
  </code></pre>
  
  <p>Any String/Array object does this automatically, if you know how this happens then please enlighten me, if not then maybe you know a way to update this custom property?</p>