title: Is it possible to implement dynamic getters/setters in JavaScript?
body: <p>I am aware of how to create getters and setters for properties whose names one already knows, by doing something like this:</p>
  
  <pre><code>// A trivial example:
  function MyObject(val){
      this.count = 0;
      this.value = val;
  }
  MyObject.prototype = {
      get value(){
          return this.count &lt; 2 ? "Go away" : this._value;
      },
      set value(val){
          this._value = val + (++this.count);
      }
  };
  var a = new MyObject('foo');
  
  alert(a.value); // --&gt; "Go away"
  a.value = 'bar';
  alert(a.value); // --&gt; "bar2"
  </code></pre>
  
  <p>Now, my question is, is it possible to define sort of catch-all getters and setters like these?  I.e., create getters and setters for any property name which <em>isn't</em> already defined.</p>
  
  <p>The concept is possible in PHP using the <code>__get()</code> and <code>__set()</code> magic methods (see <a href="http://uk3.php.net/manual/en/language.oop5.overloading.php" rel="noreferrer">the PHP documentation</a> for information on these), so I'm really asking is there a JavaScript equivalent to these?</p>
  
  <p>Needless to say, I'd ideally like a solution that is cross-browser compatible.</p>