title: Why does the javascript arguments object behave so strangely when you try to modify it?
body: <p>consider the following:</p>
  
  <p>foo intends to take the arguments object and rearrange the order, moving arg1 to the position of arg2</p>
  
  <pre><code>function foo (args) {
      args[2] = args[1];
      args[1] = undefined;
  }
  </code></pre>
  
  <p><code>bar</code> calls foo with it's arguments</p>
  
  <pre><code>function bar (a, b, c) {
      foo(arguments);
      console.log(arguments);
  }
  </code></pre>
  
  <p>I expect the result of the following to be something like <code>{ 0: 'hello', 1: undefined, 2: 'world' }</code></p>
  
  <pre><code>bar('hello', 'world');
  </code></pre>
  
  <p>However, i get:</p>
  
  <pre><code>{
      0: 'hello',
      1: undefined,
      2: 'world',
      3: undefined,
      4: undefined,
      5: undefined,
      6: undefined,
      7: undefined,
      8: undefined,
      9: undefined,
      10: undefined,
      11: undefined,
      12: undefined,
      13: undefined,
      14: undefined,
      15: undefined,
      16: undefined,
      17: undefined,
      18: undefined,
      19: undefined
  }
  </code></pre>
  
  <p>I am at a complete loss as to why this happens.
  Anyone have any ideas?</p>
  
  <p>I'm running this in a node.js environment</p>