JS anonymous function

Source: Internet
Author: User

I. Declaration and use of anonymous functions
1. Declare an anonymous function that assigns a value directly to an event;

2. Use an anonymous function expression. Assign the anonymous function to a variable.
Disclaimer: Var func=function () {}
Call: Func ();


Note: When using an anonymous function expression, the function's call statement must be placed after the function declaration statement!!! (The difference from a normal function)
"sequence of execution of JS code"
JS code is divided into two parts when it is run. Check the loading and execution phases. Check the load stage: The syntax error of the code is detected first, and the declaration of the variable and function
Execution Phase: The assignment of variables, the invocation of functions, etc., all belong to the execution phase.
The following code is an example:


cause: The preceding code is executed in the following order:
---------------Check the load stage--------------
var num;
function Func1 () {};
function Func2;


---------------Execution Phase--------------
console.log (num);
func1 ();
Func2 () =function () {};

3. Self-executing function:
1) You can use a variety of operators to start but generally use!

! function (formal parameter list) {} (argument list)
2) use () wrap the function and the parentheses after the function
(function () {} ());
3) use () value wrap function value
( function () {}) ();
Three types of writing features :
1) Use! Opening, clear structure, not easy to confuse, recommended use;
2) can be anonymous function and call () as a whole, the official recommended use;
3) It is not possible to indicate the integrity of the function and subsequent (), and is not recommended.

internal properties of the function
1.Arguments Objects
1) Function: Used to store all arguments when the function is called.
>>> When a function is called and assigned a value with an argument, the argument list is actually saved to the arguments array, which can be called in the function, using arguments[n], and N starts at 0.
2) The number of arguments arrays, depending on the argument list, regardless of the parameter. However, once the nth position of the formal parameters, arguments, arguments are present, the shape arguments and arguments bound, synchronous change. That is, in the function, modify the value of the parameter, the arguments will also change, and vice versa is also set.
3) Arguments.callee is an important attribute of arguments. Represents the reference address of the function where the arguments is located;
inside the function, you can call the function itself using Arguments.callee ().
inside the function, the invocation of the function itself is called recursion .
recursion is divided into two parts: recursion and attribution. The function can be divided into the upper and lower parts by using recursive call statements as bounds.
Recursive : When the function executes the upper part. When encountering its own invocation statement, proceed to the inner layer function and execute the upper part. Until the most inner function is executed.
return : When the inner function is executed, the bottom half of the function is gradually executed, starting from the inner function.

when the outermost function executes, it encounters its own invocation statement, which goes into the inner function execution, while the second half of the outer function is not executed. Until the most inner function is executed, step outward.

Location Object
Fetch the URL address information of the browser;
the full URL path:
protocol Name://Host name (IP address): Port number/file path? Pass-through parameters (name1=value1&name2=value2) #锚点
For example:
Http://127.0.0.1:8080/wenjian/index.html?name=jredu#top

other ways to jump pages using location-provided methods

history: Browsing the past



JS anonymous function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.