1. Preface
Arguments, caller, what is callee?
What is the role in JavaScript? This article will do some basic introduction.
This article was reproduced from: http://blog.csdn.net/oscar999/article/details/8511335
2. Arguments
Arguments: When a function is called, a hidden object named arguments is automatically generated inside the function. The object is similar to an array, but not an array. You can use the [] operator to get the arguments that are passed when the function is called.
<!--by oscar999 2013-1-16--> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > functionTestarg () {alert ("Real parameter count:" +arguments.length); for(vari = 0; i < arguments.length; i++) {alert (arguments[i]); }} testarg (11);//count:1Testarg (' Hello ', ' world ');//Count:2</script> </body> It looks simple. It is important to note that the argument holds the information of the arguments.
It says that arguments is not an array. Follow the sections below to find out
(function () { instanceof// false alert (typeof // object }) ();
The arguments object is created only when the function is called, and its value is null when it is not called:
Alert (new Function (). arguments); // return null
The complete syntax for arguments is as follows:
3. Caller
When a function calls another function, the called function automatically generates a caller property that points to the function object that called it. If the function is not currently called, or is not called by another function, caller is null.
<script> function testcaller () { var caller = Testcaller.caller; alert (caller); } function Acaller () { testcaller (); } Acaller ();
4. calleeWhen a function is called, its Arguments.callee object points to itself, which is a reference to itself.
Because arguments is valid when a function is called, Arguments.callee does not exist when the function is not called (that is, Null.callee), and the dereference causes an exception
<script> function Acallee (ARG) { alert (Arguments.callee); } function Acaller (arg1, arg2) {Acallee ();} Acaller (); </script>
Introduction to arguments, caller, and callee of "turn" JavaScript