Three ways to create objects
Method 1:
var obj = new Object();
obj.property = value;
//Continue to add other properties
obj.method = function (parameter) {
//Function Code
}
//Continue to add other methods
Method 2:
var obj = {
Attribute: value,
//Continue to add other attributes,
Method: function (Parameter) {
Function code
} ,
//Continue to add other methods
}
The above two methods directly create an object
Method 3:
/ /First define the model of the object, which can also be understood as the class
function obj (parameter) {
this.attribute = value;
//Continue to add other attributes
}
obj .prototype.method = function (parameter) {
//Function code
....
}
//Continue to add other methods
//According to the object model Instantiate object
var aTest = new obj (parameter)