title: Possible to loop over properties to dynamically define getters/setters?
body: <p>Assuming the following:</p>
  
  <pre><code>var first = {
      bob: null,
      jim: null,
      sue: null
  },
  second = {};
  </code></pre>
  
  <p>I'd like to be able to loop over the properties of <code>first</code> and define getters/setters on <code>second</code> for each; something like the following:</p>
  
  <pre><code>for (var name in first) {
      Object.defineProperty(second, ('' + name), {
          get: function() {
              return first[name];
          },
          set: function(value) {
              first[name] = value;
          }
      });
  }
  </code></pre>
  
  <p>The problem is the getters/setters seem to only affect the last property iterated over, in this case <code>sue</code>.</p>
  
  <p>However, the following seems to work just fine:</p>
  
  <pre><code>var second = {
      get bob() {
          return first['bob'];
      },
      set bob(value) {
          first['bob'] = value;
      },
      get jim() {
          return first['jim'];
      },
      set jim(value) {
          first['jim'] = value;
      },
      get sue() {
          return first['sue'];
      },
      set sue(value) {
          first['sue'] = value;
      }
  };
  </code></pre>
  
  <p>I know this has to be something obvious I'm missing, but I couldn't seem to find another question on here that accurately addresses how to accomplish this.</p>
  
  <p>Thanks in advance!</p>