Javascript shallow copies
<p>I'm fairly new to Javascript and ran into a problem with object references. Here's a snippet of the code that reproduces the issue.</p>

<pre><code>function MyVector() {
    this.x = 0;
    this.y = 0;
}

function MySprite() {
    this.pos = new MyVector();
}

var my_sprite = new MySprite(); 
var my_pos = my_sprite.pos;    // my_pos points to my_sprite's vector
var my_vect = new MyVector();  // my_vector is on the heap
my_vect.x = 69;

print("my_pos.x: " + my_pos.x);  // prints 0 (expected)

my_sprite.pos = my_vect;         // should point to my_vect

print("my_sprite.pos.x: " + my_sprite.pos.x); // prints 69 (expected)
print("my_pos.x: " + my_pos.x);  // prints 0, expected to print 69
</code></pre>

<p>In the last print statement, I would've expected my_pos.x to print 69 since my_pos now refers to my_vect (or does it?). My understanding of Javascript is that only primitive values are actually copied and that object assignment maintains a reference to a single copy of the object. It looks like after the assignment of my_vect, the my_pos reference is somehow "detached" and no longer points to my_sprite.pos.</p>

<p>Is there some behavior of Javascript that I'm overlooking here?</p>

<p>Thanks!</p>
