Home > Web Front-end > JS Tutorial > body text

js arguments,jcallee caller usage summary_javascript skills

WBOY
Release: 2016-05-16 17:11:36
Original
916 people have browsed it

Keywords: arguments, callee, caller
arguments: Represents the parameters passed into the function
callee: Represents the statement of the function and the function body
caller: Represents the function that calls the function

arguments

This object represents the function being executed and the parameters of the function that calls it.

caller

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

Explanation
For functions, the caller attribute is only defined when the function is executed. If the function is called from the top level, caller contains null . If the caller attribute is used in a string context, the result is the same as functionName.toString, that is, the decompiled text of the function is displayed.

callee

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

[function.]arguments.callee

The optional function parameter is the name of the Function object currently being executed.

Description

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

The callee attribute is a member of the arguments object. It represents a reference to the function object itself, which is beneficial to the recursion of anonymous functions or to ensure the encapsulation of functions. For example, the following example recursively calculates the sum of natural numbers from 1 to n. This property is only available when the relevant function is executing. It should also be noted that callee has a length attribute, which is sometimes better for verification. arguments.length is the actual parameter length, and arguments.callee.length is the formal parameter length. From this, you can determine whether the formal parameter length is consistent with the actual parameter length when calling.

Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template