First, the concept of factory model
The factory pattern defines an interface for creating objects that the subclass determines which class to instantiate. This pattern delays the instantiation of a class to a subclass. A subclass can override an interface method to specify its own object type (abstract factory) when it is created.
This pattern is useful, especially when creating an object's process assignment, such as relying on many settings files. Also, you will often see a factory method in a program that allows subclasses to define the type of object that needs to be created.
Second, the role of the factory model and matters needing attention
Mode function:
1, the object construction is very complex--we wear shoes is very simple, but the process of making shoes is very complicated
2, need to rely on a specific environment to create a different example-the factory can make shoes, make clothes, the factory can do I need shoes (shoes are different), and then sent to the designated place (place can be different), can be understood as a different example
3, processing a large number of small objects with the same attributes-such as buying a pair of shoes, there is no need to find factory production
Precautions:
1, can not abuse the factory, and sometimes just to increase the complexity of the code-as above 3
Third, factory model code and actual combat summary
The above is a small set to introduce the JavaScript design model of the classic factory model, I hope to help you!