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