There are three methods for creating objects in javascript. I have released a simple instance version before. For details, refer. Three methods for creating an object
Method 1:
The Code is as follows:
Var obj = new Object ();
Obj. Property = value;
// Continue adding other attributes
Obj. method = function (parameter ){
// Function Code
}
// Continue adding other methods
Method 2:
The Code is as follows:
Var obj = {
Attribute: value,
// Continue adding other attributes,
Method: function (parameter ){
Function Code
},
// Continue adding other methods
}
Both methods directly create an object.
Method 3:
The Code is as follows:
// Define the object model first, which can also be understood as a class
Function obj (parameter ){
This. Property = value;
// Continue adding other attributes
}
Obj. prototype. method = function (parameter ){
// Function Code
....
}
// Continue adding other methods
// Instantiate the object based on the object model
Var aTest = new obj (parameter)