title: Objects with their own intrinsic value. Another way to do getters
body: <p>I wanted to be able to create an object that had it's own intrinsic value.  That way I could use it in an expression as if it was a regular variable.   It turned out to be quite easy - so easy I am wondering if I am missing something.  All it seems to take is to make sure the object contains a method "valueOf". Like so:</p>
  
  <pre><code>var p = {
    a: 12;
    valueOf: function(){return this.a+12}
    }
  
  alert(p/3); // =8
  </code></pre>
  
  <p>It's probably a good idea to include a "toString" method too.  What seems to be happening is that without the valueOf method, a reference to the object goes up the prototype chain until it finds the method on Object, which just returns "object Object".   By providing a local one, the method can return anything.</p>
  
  <p>It seems to work in all browsers that I tried.   </p>
  
  <p>It is really another way to provide a getter-like functionality.  But a little better because getters can only be applied to properties of objects.  This way you can use the object itself.</p>
  
  <p>What do you think?  Is this safe?  Any pitfalls? </p>