Sample Code of the javascript custom callback function and sample code of the callback function
If you call function a directly, this callback function will be suspended. However, using a function as a parameter has the following benefits: When a (B) is used, function B becomes a callback function, and you can use a (c) as a callback function, function c becomes the callback function. If you write functiona () {...; B () ;}, the flexibility of the variable is lost.
Copy codeThe Code is as follows:
Function a (index, callback ){
Callback (index );
}
Function B (index ){
Alert (index );
}
A (10000, B );
Javascript callback function synchronization problems
First, javascript scripts are linearly executed.
<Javascript>
Operation
Operation B
Operation C
</Javascript>
If "A" is executed, B is executed before C is executed.
The reason why you say asynchronous occurs. Because you call the BMap. Map class getPoint is an ajax
This ajax is an http request. Javascript program execution is not restricted.
Because. GetPoint jumps out of this javascript script. Execute the script on your own, while the script continues with the next statement alert (d1)
So -----------
Function (point ){
If (point ){
Map. centerAndZoom (point, 16 );
Map. addOverlay (new BMap. Marker (point ));
D1 = point. lng;
}
}
----------------------
This method is executed only after ajax is reversed. Not working
So d1 does not = point. lng
If you obtain the d1 result of an ajax request
Please go
D1 = point. lng; followed:
Alert (d1 );
Callback functions in javascript
Javascript events are equivalent to anonymous functions, such as onclick ()