function varArgs(fn){

   var numberOfFixedArguments = fn.length -1,
       slice = Array.prototype.slice;          
         
                   
   if( numberOfFixedArguments == 0 ) {
      // an optimised case for when there are no fixed args:   
   
      return function(){
         return fn.call(this, slice.call(arguments));
      }
      
   } else if( numberOfFixedArguments == 1 ) {
      // an optimised case for when there are is one fixed args:
   
      return function(){
         return fn.call(this, arguments[0], slice.call(arguments, 1));
      }
   }
   
   // general case   

   // we know how many arguments fn will always take. Create a
   // fixed-size array to hold that many, to be re-used on
   // every call to the returned function
   var argsHolder = Array(fn.length);   
                             
   return function(){
                            
      for (var i = 0; i < numberOfFixedArguments; i++) {
         argsHolder[i] = arguments[i];         
      }

      argsHolder[numberOfFixedArguments] = 
         slice.call(arguments, numberOfFixedArguments);
                                
      return fn.apply( this, argsHolder);      
   }       
}
function varArgs(fn){

   var numberOfFixedArguments = fn.length -1,
       slice = Array.prototype.slice;          
         
                   
   if( numberOfFixedArguments == 0 ) {
      // an optimised case for when there are no fixed args:   
   
      return function(){
         return fn.call(this, slice.call(arguments));
      }
      
   } else if( numberOfFixedArguments == 1 ) {
      // an optimised case for when there are is one fixed args:
   
      return function(){
         return fn.call(this, arguments[0], slice.call(arguments, 1));
      }
   }
   
   // general case   

   // we know how many arguments fn will always take. Create a
   // fixed-size array to hold that many, to be re-used on
   // every call to the returned function
   var argsHolder = Array(fn.length);   
                             
   return function(){
                            
      for (var i = 0; i < numberOfFixedArguments; i++) {
         argsHolder[i] = arguments[i];         
      }

      argsHolder[numberOfFixedArguments] = 
         slice.call(arguments, numberOfFixedArguments);
                                
      return fn.apply( this, argsHolder);      
   }       
}
function varArgs ( fn ) { var numberOfFixedArguments = fn . length - 1 , slice = Array . prototype . slice ; if ( numberOfFixedArguments == 0 ) { // an optimised case for when there are no fixed args:    return function ( ) { return fn . call ( this , slice . call ( arguments ) ) ; } } else if ( numberOfFixedArguments == 1 ) { // an optimised case for when there are is one fixed args: return function ( ) { return fn . call ( this , arguments [ 0 ] , slice . call ( arguments , 1 ) ) ; } } // general case    // we know how many arguments fn will always take. Create a // fixed-size array to hold that many, to be re-used on // every call to the returned function var argsHolder = Array ( fn . length ) ; return function ( ) { for ( var i = 0 ; i < numberOfFixedArguments ; i ++ ) { argsHolder [ i ] = arguments [ i ] ; } argsHolder [ numberOfFixedArguments ] = slice . call ( arguments , numberOfFixedArguments ) ; return fn . apply ( this , argsHolder ) ; } }
Define variable argument functions but cut out all that tedious messing about
with the arguments object. Delivers the variable-length part of the arguments
list as an array.

Eg:

var myFunction = varArgs(
function( fixedArgument, otherFixedArgument, variableNumberOfArguments ){
console.log( variableNumberOfArguments );
}
)

myFunction('a', 'b', 1, 2, 3); // logs [1,2,3]

var myOtherFunction = varArgs(function( variableNumberOfArguments ){
console.log( variableNumberOfArguments );
})

myFunction(1, 2, 3); // logs [1,2,3]
Define variable argument functions but cut out all that tedious messing about with the arguments object . Delivers the variable - length part of the arguments list as an array .
This function is a function that takes a number of arguments and returns a function that will return a new object with the arguments as the first argument.