1: Constructor method ]
Note:
1 : A Dog object is defined here (in JavaScript, a function is an object, here function Dog(name,weight) is also a constructor), and an object instance dog is created using the new keyword.
2: Among them, _name, _weight, _show, and _sex are the attributes of the instance dog. Instance attributes can be accessed through: instance name.attribute name or instance name ["attribute name"], that is, dog._name=dog["_name"].
3: The attributes in the constructor (here function Dog(name,weight) is also a constructor) will be attached to all instances, for example: var dog1=new Dog(…);dog1 will have _name, _weight, _show attributes, but the _sex attribute is only exclusive to the dog instance, it will not be loaded to other objects.
2: Object creation method:
The object object provides a simple method to create custom objects without defining a constructor.
If you need to introduce external Js, you need to refresh to execute
]
Note:
Here A cat instance is created using the Object object. 3: Object initializer method
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
] Note: 1 , here we have actually implemented static properties and methods, without creating an instance.
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