title: Prototyping "arguments"
body: <p><strong>Introduction</strong></p>
  
  <p>We all know these silly <code>arguments</code> objects of JavaScript functions.</p>
  
  <blockquote>
    <p>But why object? Isn't it an array?</p>
  </blockquote>
  
  <p>No, it's not and that's why a lot people call it a failure in JavaScripts concept:</p>
  
  <pre><code>(function () {
      return arguments.slice(); // TypeError: arguments.slice is not a function
  }());
  </code></pre>
  
  <hr>
  
  <p><strong>Intention</strong></p>
  
  <p>Okay, that's just an introduction to the real thing I'd like to ask, but before asking you need some more information:</p>
  
  <p>While reading different code during the last days, I got quite scarry while seeing the following line of code in quite a lot places.</p>
  
  <pre><code>args = Array.prototype.slice(arguments);
  </code></pre>
  
  <p>So, what does it do, is simply "converting" the <code>arguments</code> object into an array with all of its prototypes and stuff.</p>
  
  <hr>
  
  <p><strong>My solution</strong></p>
  
  <p>What I thought of was the following: While JavaScript is all about prototyping, why don't we extend the <code>arguments</code> object's <code>prototype</code> itself? I checked some sites for existing scripts, but found nothing I was intended to find and finally got to write it myself:</p>
  
  <pre><code>(function () {
      var i, methods;
  
      arguments.constructor.prototype = Array.prototype;
      methods = ['concat', 'join', 'pop', 'push', 'reverse', 'shift', 'slice', 'sort', 'splice', 'toString', 'unshift'];
  
      for (i = 0; i &lt; methods.length; i += 1) {
          if (arguments.constructor.prototype.hasOwnProperty(methods[i]) === false) {
              arguments.constructor.prototype[methods[i]] = Array.prototype[methods[i]];
          }
      }
  }());
  </code></pre>
  
  <p>After compression it takes 260 byte only and extends the <code>arguments</code> object's <code>prototype</code> by using <code>Array.prototype</code>.</p>
  
  <p>So finally I can handle <code>arguments</code> objects just the same way as "real" arrays.</p>
  
  <hr>
  
  <p><strong>The question</strong></p>
  
  <p>After checking the most famous JavaScript frameworks I finished with the following: none uses such a construct and extends the <code>arguments</code> object's <code>prototype</code>.</p>
  
  <p>But why? Is there anything wrong with, I don't think of right now?</p>