title: How to create a variadic (with variable length argument list) function wrapper in JavaScript
body: <p>The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines.<br>
  I am aware of 3 methods of which each one has its own drawbacks.</p>
  
  <ol>
  <li><p><code>eval()</code> method:</p>
  
  <pre><code>function wrapper () {
      var str = '';
      for (var i=0; i&lt;arguments.lenght; i++)
          str += (str ?', ':'') + ',arguments['+i+']';
      return eval('[native_function] ('+str+')');
      }
  </code></pre></li>
  <li><p><code>switch()</code> method:</p>
  
  <pre><code>function wrapper () {
      switch (arguments.lenght) {
          case 0:
              return [native_function] (arguments[0]);
              break;
          case 1:
              return [native_function] (arguments[0], arguments[1]);
              break;
          ...
          case n:
              return [native_function] (arguments[0], arguments[1], ... arguments[n]);
          }
      }
  </code></pre></li>
  <li><p><code>apply()</code> method:</p>
  
  <pre><code>function wrapper () {
      return [native_function].apply([native_function_namespace], arguments);
      }
  </code></pre></li>
  </ol>
  
  <p>What's wrong with them you ask?</p>
  
  <ol>
  <li><p>Well, shall we delve into all the reasons why <code>eval()</code> is evil? And also all the string concatenation... Not a solution to be labeled "elegant".</p></li>
  <li><p>One can never know the maximum <code>n</code> and thus how many <code>cases</code> to prepare. This also would strech the script to immense proportions and sin against the holy <em>DRY</em> principle.</p></li>
  <li><p>The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don't support the <code>apply()</code> method.</p></li>
  </ol>
  
  <p>Now the question part: is there any another solution out there?</p>