title: Does javascript handle objects by reference or by value?
body: <p>I have this code</p>
  
  <pre><code>var myObjects = {}; //global variable
  
  //Later on in the code:
  for (i in myObjects)
  {
      var obj = myObjects[i];
      process(obj);
  }
  
  function process(obj)
  {
      $.getJSON("example.com/process/", {id: obj.id}, function(result)
        {
            //Will the following change the permanent/global copy e.g 
            // myObjects[44] ?
            obj.addItem(result.id, result.name, result.number);
        }
      );
  }
  </code></pre>
  
  <p>Will the following line:</p>
  
  <pre><code>     obj.addItem(result.id, result.name, result.number);
  </code></pre>
  
  <p>modify the object by value or by reference, i.e will it modify the local copy of <code>obj</code> or e.g <code>myObjects[44]</code>?</p>
  
  <p>If it affects only the local copy, how can I have it change the global copy of the object?</p>