Individual instances, individual individual---Singleton mode
Long long ago, there was only a basic data type in JS.
I want to describe a person
var name = "Side East strategy";
var age = 28;
var height = "148cm";
var weight = "200kg";
I want to describe the second person.
var name = "Li Jianjie";
var age = 18;
var height = "188cm";
var weight = "60kg";
Now that we have a problem, the information we described later covers the first person's information. The conflict between variables and the pollution of global variables
In order to put together the characteristics that describe the same thing, and to avoid conflicts with other things, we introduce the object data type---> We call this writing pattern "singleton mode".
1) Implement grouping--and the same "namespace" (opening a space with a name) the singleton pattern is to put all the attributes and methods of describing this thing under the same namespace, realizing the function of grouping under the namespace.
2) Avoid conflicts--different namespaces are non-impact
var Person1 = {
Name: "Side East Strategy",
Age:28
};
var Person2 = {
Name: "Li Jianjie",
Age:18
};
Console.log (Person2.name);
Console.log (Person1.age);
We can implement the simplest modular development in a real project by applying a singleton pattern
"Modular Development": A site according to the function divided into a few chunks, and then by a team of multi-person collaboration between the development, everyone responsible for the corresponding parts, and finally in the code to merge, compress, upload ...
Lesson NOTES:--Creating an object's singleton pattern