How to control execution sequence of callback functions of js asynchronous operations _ javascript skills

Source: Internet
Author: User
This article explains how to control the execution sequence of callback functions in js asynchronous operations. If you are interested, refer to the following requirements:
Fun A () {asyn (parm1, parm2, onsuccess (){});}
Fun B () {asyn (paem1, parm2, onsuccess (){});}

Function B must be executed after function.

Asynchronous execution
If you directly use
A ();
B ();

The execution conditions cannot be met.

Consider passing B as the callback function to A, and then executing the B function in the onsucess that A executes again.
A (B );

To meet the functional requirements.

Js is single-threaded.

1. When a function is called, if the number of parameters exceeds the defined number, extra parameters will be ignored, if the number is less than the defined number, the number of missing parameters is automatically assigned to the undefined value.
2. If a function definition is declared using a function statement, it cannot appear in a loop or condition statement, however, if the function is defined using the function method directly, it can appear in any js expression.
3. arguments object
The arguments object of the function is like an array, which stores the actual parameters used for the function call. You can use arguments [0], arguments [1], arguments [2]… And so on, even if these parameters do not exist when defining the function. But arguments is not a real array object.
Function a (x, y ){
Arguments [0] // indicates the first parameter x
Arguments [1] // indicates the first parameter y
Arguments [2] // indicates the third parameter, provided that three parameters are input when the function is called.
...
Arguments. length // indicates the number of actually passed parameters.
Arguments. callee (x, y) // call itself}
The arguments object has the length attribute, indicating the number of parameters actually passed in when a function is called.
The arguments object also has the callee attribute to reference the currently executed function, which is particularly useful in anonymous functions.
4. The length attribute of the function (yes, the function also has the length attribute)
Unlike arguments. length, the length attribute of a function indicates the number of form parameters when defining a function, rather than the actual number of parameters when calling a function. You can use arguments. callee. length to call the length attribute of a function.
Related Article

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.