Sample Code of the javascript custom callback function and sample code of the callback function

Source: Internet
Author: User
Tags map class

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 ()

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.