JavaScript design pattern classic Command pattern _ javascript skills

Source: Internet
Author: User
Command is defined as a parameter processing and transmission of method calls. a method call that has been processed in this way can be executed as needed. Next, we will use this article to introduce you to the typical JavaScript design mode command mode. For more information, see I. concept of command mode

Command is defined as a parameter processing and transmission of method calls. a method call that has been processed in this way can be executed as needed. That is to say, this mode aims to encapsulate function calls, requests, and operations into a single object, and then process this object with some columns. It can also be used to eliminate coupling between objects that call operations and objects that implement operations. This brings great flexibility for the replacement of various specific classes.

II. Functions and precautions of the command mode

Role of the mode:

1. integrate function encapsulation, requests, and calls

2. call specific function decoupling command objects and receiving objects

3. improve the flexibility of program modularization

Note:

1. you can directly call the function without excuses for consistency to avoid waste.

III. command mode code and practical summary

 Script // 1. the commander can run commands to mobilize the army to fight with artillery and infantry. var lian ={}; lian. paobing = function (pao_num) {console. log (pao_num + "warehouse guard prepare for battle");} lian. bubing = function (bubing_num) {console. log (bubing_num + "prepare for battle");} lian. lianzhang = function (mingling) {lian [mingling. type] (mingling. num);} // command lian. lianzhang ({type: "paobing", num: 10}); lian. lianzhang ({type: "bubing", num: 100}); script

The above section describes the typical JavaScript design mode of the command mode. I hope it will be helpful to you!

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.