JavaScript design Pattern--an example of appearance pattern _javascript skills

Source: Internet
Author: User

Appearance mode (façade mode) is a relatively simple and ubiquitous pattern. The appearance mode provides a high-level interface that makes it easier to invoke the client or subsystem.

With a simple code that says:

Copy Code code as follows:

var getName = function () {
Return "Svenzeng"
}
var getsex = function () {
Return ' Mans '
}

If you need to call the GetName and Getsex functions separately. That can be invoked with a higher-level interface GetUserInfo.

Copy Code code as follows:

var getuserinfo = function () {
var info = a () + B ();
return info;
}

The answer is obvious, the chef of the canteen will not be because you ordered a roast duck and a cabbage to fry the two dishes in a pot. He is more than willing to offer you a roast duck meal package. Also in the program design, we need to ensure that the function or object as far as possible in a reasonable granularity, after all, not everyone likes to eat roast duck and just like to eat cabbage.

Another benefit of the skin pattern is that you can hide real implementation details from users, who only care about the top-level interface. For example, in the story of the Roast duck meal package, you don't care whether the chef cooks first or fry the cabbage first, and you don't care where the duck grew up.

Finally, let's write an example of a pattern that we've all used:

Copy Code code as follows:

var stopevent = function (e) {//block event default behavior and bubbling
E.stoppropagation ();
E.preventdefault ();
}

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.