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)
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn