A brief analysis of the difference between arguments and arguments.callee in Javascript


To understand the specific difference between arguments and arguments.callee by using an example:

The code is as follows:

<script type="text/javascript">        
        function check(args){            
            var ac = args.length
            var ex = args.callee.length
            document.write("ac:" + ac + '<br>'); 
            document.write("ex:" + ex + '<br>'); 
            if (ac != ex) { 
                document.write("wrong number of arguments: expected: " + ex + "; actually passed" + ac + '<br>'); 
            } 
        } 
        function f(x, y, z) { 
            check(arguments); 
            document.write(x + y + z); 
        }             
    </script> 

Call method:

<input name="wr" type="button" value=" call " onclick="f(1,2)" /> 

The result after operation is:

ac:2
ex:3
wrong number of arguments: expected: 3; actually passed2
NaN

My understanding:

arguments is the calling object, the object that calls this method arguments.callee is the current object, which in effect returns the currently executing function object And you can see that in this example arguments actually means the function “f(1,2)” argument.callee actually means “function f(x,y,z){}”