Js arguments jcallee caller usage summary

  • 2020-03-30 00:39:06
  • OfStack

Key words: the arguments, the callee, caller
Arguments: represents an argument to the passed function
Callee: a statement that represents a function and its body
Caller: represents the function that calls the function

The arguments

This object represents the arguments to the function being executed and to the function calling it.


Returns a reference to a function that calls the current function.
FunctionName. The caller
The functionName object is the name of the function being executed.

For functions, the caller property is defined only when the function executes. If the function is called from the top level, the caller contains null. If the caller property is used in the string context, the result is the same as functionname.tostring, that is, the decompressed text of the function is displayed.

The callee

Returns the body of the Function object being executed, that is, the specified Function object.

[function.] the arguments. The callee

The optional function parameter is the name of the currently executing function object.


The initial value of the callee property is the Function object being executed.

The callee property is a member of the arguments object and represents a reference to the function object itself, which is good for recursion of anonymous functions or for encapsulation of functions, such as the recursion in the following example to calculate the sum of natural Numbers from 1 to n. This property is only available when the relevant function is executing. It's also important to note that callee has a length property, which is sometimes good for validation. Arguments. Length is the argument length, and arguments. Callee. Length is the argument length, so you can tell if the argument length is the same as the argument length when called.

<script type='text/javascript'>
function test(x,y,z) 
alert(" The length of the arguments :"+arguments.length);
alert(" The length of the parameter :"+arguments.callee.length);
alert(" The length of the parameter :"+test.length);
alert(arguments[ 0 ])         
alert(test[ 0 ])           //Undefined has no such use

Array.prototype.selfvalue  =   1 ;
function  testAguments() {
    alert( " arguments.selfvalue= " + arguments.selfvalue);
alert("Array.sefvalue="+new Array().selfvalue);
function  callerDemo()  {
     if  (callerDemo.caller)  {
         var  a =  callerDemo.caller.arguments[ 0 ];
    }   else   {
        alert( " this is a top function " );
function  handleCaller()  {
 handleCaller(" parameter 1"," parameter 2");

function  calleeDemo()  {
 (function(arg0,arg1){alert(" The number of the shape is :"+arguments.callee.length)})();

  function  ObjectA() {
    alert( "  perform ObjectA() " );
    alert(arguments[ 0 ]);
     this .hit = function (msg) {alert(msg)}
     this .info = "  I come from ObjectA "

  function  ObjectB() {
    alert( "  perform ObjectB() " );
     //Call the ObjectA() method, and all this in the ObjectA constructor is replaced by this in ObjectB
    ObjectA.apply( this ,arguments); // ObjectA.call(this);
    alert( this .info);
  ObjectB(' parameter 0');

  var  value = " global  variable  " ;
  function  Obj() {
     this .value = "  Object!  " ;
  function  Fun1() {
    alert( this .value);
   Fun1.apply(new Obj());

Related articles: