Simple to understand the arguments object in JavaScript

background:

When calling the function, the browser will pass two parameters to this function

  1. this: function context object, do not understand look at this
  2. arguments: the argument object encapsulates

A, arguments and what role

What it is:
Array is a class object, you can manipulate the data by index
Note: The class is an array, that is not an array, but have common properties and methods of an array

effect:
The function is called, the arguments are passed to the arguments of the package

Second, the common attributes and methods

Attributes:
callee property: the function corresponding to the object currently being pointed to

method:
arguments.length length argument can be acquired
even if the parameter is not defined, it may also be used by arguments arguments

for example:

<script type="text/javascript">
	   function fun(a,b,c){
		   console.log(arguments[0]);//输出1
		   console.log(arguments.length);//输出4
		   console.log(arguments.callee);//输出fun函数
	   }
	   fun(1,2,4,5);
</script>
He published 198 original articles · won praise 94 · views 90000 +

Guess you like

Origin blog.csdn.net/shang_0122/article/details/104654817