title: Javascript object losing properties after assignment
body: <p>This is probably a nuance of JS, but if I understood why it happens, then I can maybe come up with a workaround.  I need to be able to access object "a" and its properties, which are assigned in function f1().  However, the properties are gone when trying to access them.  Also, why does prop1 of object "b" = 1 instead of 100?</p>
  
  <pre><code>function Obj(){
  
      var a = {};
      var b = { prop1: 1, prop2: 2 };
      var c = { prop1: 1, prop2: 2 };
  
      var f1 = function(){
          a = { prop1: 1, prop2: 2 };
  
          // in real life this calls a function that returns an object
          // a = someOtherFunctionThatReturnsAnObject();
      };
  
      var f2 = function(){
          b = { prop1: 100, prop2: 200 };
      };
  
      var vm = {
          f1:f1,
          f2:f2,
          a:a,
          b:b,
          c:c
      };
      return vm;
  }
  
  var obj = new Obj();
  obj.f1();
  obj.f2();
  
  alert (obj.a.prop1);   // undefined
  alert (obj.b.prop1);   // 1   * Why not 100? *
  alert (obj.c.prop1);   // 1
  </code></pre>