Method of JS Encapsulation

Source: Internet
Author: User

1, JS package is to try to use the way to simplify, internal logic and use decoupling. In layman's terms, you only need to know the parameters and return values when you use them, and other conditions try not to use people to set them up.

2, the method of JS package has the function way, the way of the object, the way of closing the packet.

Example

1) function mode
function KK (A, b) {
There is no need to worry about how to deal with A/b internally.
}

2) Object mode
function KK (A, b) {
This.x = A;
This.y = b;
}
var k = new KK;//through object-oriented approach
alert (k.x);
3) Closure method
function KK (A, b) {
var k = 1;
return function tt () {
k++;
}
}
var u = KK (on);
U ();//Closure Implementation cumulative
U ();//Closure Implementation cumulative

Method of JS Encapsulation

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.