JavaScript acquired parameter length and length arguments

1. Get the number of arguments

  Get the length argument can be used directly arguments.length, arguments is the argument object is an array type, with a length property represents the number of arguments, like an array may be acquired by the value of the argument index, e.g. arguments [0]

  function fun(a, b, c) {

    console.log(arguments.length);

    console.log(arguments[0]);

  }

  fun(1, 2, 3);

  Console print out the results:

  3

  1

 

2. Get the number of parameter

  Get the number of parameter in two ways:

  2.1 function name .length

    function fun(a, b, c) {

      console.log(fun.length);

    }

  2.2 arguments.callee.length 

    arguments.callee The property is a pointer to the object's function has arguments, whenever function uses the arguments object is created, we have to call the function fun (); then the fun there argumnets, so arguments.callee means It is the current function

    function fun(a, b, c) {

      console.log(arguments.callee.length);

    }

Guess you like

Origin www.cnblogs.com/hebing0415/p/11462900.html