JavaScript Design Patterns

Source: Internet
Author: User

Because I am just a front-end novice, just learn JavaScript, so the article inevitably will appear some mistakes. If you see the error of the article, please point out, I will change in time, thank you!

Factory mode is a well-known design pattern that provides an interface for creating objects that are generated according to the parameters of the caller. by using the Factory mode instead of the new keyword and the concrete class, you can centralize all the instantiated classes in one place and use functions to encapsulate the details of creating objects with specific interfaces. Give an example to illustrate:

function Createperson (name, age, Job) {   varnew  Object ();    = name;    = Age ;    = job;    function () {        alert (this. Name);   };    return o;     }     var person1 = Creatperson (' Zhang San ', ' software Engineer '); var = Creatperson (' John Doe ', Person2, ' Doctor ');

Not finished, to be continued ....

JavaScript Design Patterns

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.