Returns the arguments object for the currently executing Function object.function.argumentsThe function argument is the name of the currently executing function, and can be omitted. Res
The arguments property allows a function to handle a variable number of arguments. The length property of the arguments object contains the number of arguments passed to the function. The individual arguments contained in the arguments object can be accessed in the same way array elements are accessed.Example
The following example illustrates the use of the arguments property:function ArgTest(){
   var i, s, numargs = arguments.length;
   s = numargs;  
   if (numargs < 2)
      s += " argument was passed to ArgTest. It was ";
   else
      s += " arguments were passed to ArgTest. They were " ;
   for (i = 0; i < numargs; i++)
      {
         s += arguments[i] + " ";
      }
   return(s);
}

解决方案 »

  1.   

    运行下面的函数,函数使用参数对象并类似于数组的访问方式得到参数a,b,
    function ArgTest(a, b){
       var i, s = "The ArgTest function expected ";
       var numargs = arguments.length;     //Get number of arguments passed.
       var expargs = ArgTest.length;       //Get number of arguments expected.
       if (expargs < 2)
          s += expargs + " argument. ";
       else
          s += expargs + " arguments. ";
       if (numargs < 2)
          s += numargs + " was passed.";
       else
          s += numargs + " were passed.";
       s += "\n\n"
       for (i =0 ; i < numargs; i++){      //Get argument contents.
       s += "  Arg " + i + " = " + arguments[i] + "\n";
       }
       return(s);                          //Return list of arguments.
    }