An interpretation of the concept of single-case model
1. Single-case model concept text interpretation
A single example is to ensure that a class has only one instance, the method of implementation is generally first to determine whether the instance exists or not, if there is a direct return, if it does not exist to create a return, this ensures that a class has only one instance object. In JavaScript, a singleton serves as a namespace provider, providing a unique access point from the global namespace to access the object.
2. Simple interest model concept of quasi-materialized interpretation
Buy a house first to confirm whether there is a door, not to contact the developer to create. Second, each door has its own ownership, 301 belong to Xiao Wang, 302 belong to Xiao Li, Xiao Wang Xiao Li belongs to the name space, but a building there are several small Wang Xiao Li, these global namespaces in the 301 belong to a small king, that is, provide a unique access point to access the object.
Second, the role of the single-case model and matters needing attention
Mode effect:
1. Inter-module communication.
2. There can be only one object for a class in the system.
3. Protect your own properties and methods.
Precautions:
1. Note the use of this (who is called, who points to).
2. Closures are prone to memory leaks, eliminating the need to quickly delete them.
3. Pay attention to the cost of new. Inheritance
The Code Combat and summary of the single case model
A single-instance pattern of JavaScript design Patterns