title: Javascript Object Properties Calculated (on the fly) from Other Object Properties
body: <p>I am trying to create a javascript object that calculates various values for the properties set on it. I have compiled this simple example of what I am trying to achieve: <strong><a href="http://jsfiddle.net/jrulle/jrbvy12k/2/" rel="noreferrer">JSFIDDLE</a></strong></p>
  
  <pre><code>var obj = {};
  obj.a = 2;
  obj.b = 5;
  obj.avg = "(obj.a + obj.b)/2"; 
  obj.rounded = "Math.floor(eval(obj.avg))";
  
  console.log("rounded avg: " + eval(obj.rounded));
  //simulate changing properties
  obj.a = Math.floor(Math.random() * 10);
  obj.b = Math.floor(Math.random() * 10);
  console.log("rounded avg: " + eval(obj.rounded));
  </code></pre>
  
  <p>The above code currently achieves what I want (using standard set values like 'a' and 'b' to calculate 'avg' then using 'avg' in a second calculation 'rounded'). </p>
  
  <p>Is there a better way to achieve this (ideally without the <code>eval()</code> calls whenever a calculated property is referenced in another property). </p>
  
  <p>What I would like is for the calculated properties to act like functions (calculate their value whenever they are referenced) rather than calculating their value initially and not changing - I would like to avoid having to use <code>()</code> to call the functions (so that I can reference both the plain values and the calculated values the same way - just by their property name).</p>