Module mode and reveal mode.

Source: Internet
Author: User

---restore content starts---

Module mode: A way to provide private and public encapsulation of classes in traditional software engineering.

In JS: Module mode uses closures to encapsulate private state and organization. This mode returns a public API, while everything else remains in the private closure.

Since JS does not have access modifiers, we cannot call variables public or private, so we need to use function scopes to simulate this concept.

 

Advantages of using module mode:

1) Only our modules can enjoy the freedom to have private functions.

2) The discovery of function anomalies becomes much easier.

3) more tidy.

4) Support private data.

Disadvantages:

1) Change the visibility of the member and need to change every place where the member has been used.

Reveal mode:

Returns an anonymous object that has a pointer to a private function.

Pros: Make scripting syntax consistent and easy to point out which functions and variables can be accessed publicly.

Cons: If a private function refers to a public function, the public function cannot be overwritten when patching.

Module mode and reveal mode.

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.