------"Event snooping" for JavaScript asynchronous programming methods

Source: Internet
Author: User

------"Event snooping" for JavaScript asynchronous programming methods
Another way of thinking is to use event-driven mode. The execution of a task does not depend on the order of the Code, but on whether an event occurs.
Take F1 and F2 as an example. First, bind an event for F1 (the jquery notation used here).
F1.on (' Done ', F2);
The above line of code means that when a done event occurs on F1, the F2 is executed. Then, rewrite the F1:
Function F1 () {setTimeout (function () {///F1 Task Code F1.trigger (' Done ');
}, 1000);
}
F1.trigger (' Done ') indicates that when execution is complete, the Do event is immediately triggered to begin execution of F2.
The advantages of this method are relatively easy to understand, can be bound to multiple events, each event can specify multiple callback functions, and can be "decoupling" (decoupling), is conducive to the implementation of modularity. The downside is that the entire program becomes event-driven, and the running process becomes unclear.

------"Event snooping" for JavaScript asynchronous programming methods

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.