title: How does javascript x = y work when dealing with objects?
body: <p>I am working with Omniture tagging and I've got numerous events on the page.  In omniture, the base object is <code>s</code> this object is created globally by Omniture.</p>
  
  <p>The <code>s</code> object has a number of "standard" variables that I like to set for it, url, pagetitle, time on site, what have you...  </p>
  
  <p>For each event I set one or two additional properties</p>
  
  <p>I thought I was being really clever in writing functions like:</p>
  
  <pre><code> //  s is a global variable create by omniture
  
   function ClickFoo(){
        var s_ = s;  // make a copy of s which has all the standard vars
        s_.event = "Click Foo";  // set X number of custom vars 
        s_.prop1 = "foo";
        s_.t();    // the Omniture "submit event" function
   }
  
   function ClickBar(){
        var s_ = s;
        s_.event = "Click Bar";
        s_.prop2 = "bar";
        s_.t();    
   }
  
   ClickFoo();
   ClickBar();
   // at this point, s.prop1 = "foo"
  </code></pre>
  
  <p>If the user clicks <code>foo</code> then <code>bar</code> the <code>s_.prop1</code> object property is set on the bar submit. </p>
  
  <p>I've been looking at the behavior of this stuff in the JS console and it seems that changes to s_ have an effect on the global object s. </p>
  
  <p>Can anyone explain how the assignment is working so I don't make this mistake in future?  Is there a quick way to do this correctly?</p>