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

How to control the execution order of js asynchronous operation callback function_javascript skills

WBOY
Release: 2016-05-16 17:07:27
Original
1331 people have browsed it

Requirements:
fun A() { asyn(parm1, parm2, onsuccess(){ }) ;}
fun B() {asyn(paem1, parm2, onsuccess(){}) ;}

Function B requires execution after function A

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

, the execution conditions cannot be met of.

Consider passing B as a callback function to A, and then A executes the B function in the onsucess
A (B);

to achieve the functional requirements.

js is single-threaded.

1. When calling a function, if there are more parameters than the number of definitions, the extra parameters will be ignored. If they are less than the number of parameters, number, the missing parameter number will automatically be assigned the undefined value.
2. If the function definition is declared with a function statement, it cannot appear in a loop or conditional statement, but if the function definition is declared with a function literal method, it can appear in any js expression.
3. arguments object
The arguments object of a function is like an array, which stores the actual parameters when the function is called. These can be referenced using arguments[0], arguments[1], arguments[2], etc. Parameters, even if these parameters are not present when the function is defined. But arguments are not real array objects.
function a(x,y){
arguments[0] //Represents the first parameter x
arguments[1] //Represents the first parameter y
arguments[2] // Represents the third parameter, provided that three parameters are passed in when calling the function
...
arguments.length //Represents the actual number of parameters passed in
arguments.callee(x,y) / /Call itself}
The arguments object has a length attribute, which represents the number of parameters actually passed in when the function is called.
The arguments object also has a callee attribute, which is used to reference the currently executing function. This is especially useful in anonymous functions.
4. The length attribute of the function (yes, the function also has the length attribute)
Different from arguments.length, the length attribute of the function represents the number of formal parameters when defining the function, not the function call the actual number of parameters. You can use arguments.callee.length to call the length property of a function.

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