An object is a collection of properties and methods. What is object-oriented? Object-oriented is a programming idea and a concept. In js, object-oriented programming is implemented through a method called prototype.
Create a student object
{Attribute 1: value 1, attribute 2: value 2, attribute 3: value 3}
json data format: It is a data conversion format
01. It is in the form of a key-value pair
02. The object is saved in {}
03. The collection is saved in []
04. Data is separated by commas, and attributes and attribute values are separated by colons
Note point:
01. All objects have a constructor attribute! Points to the constructor!
02. When we create a function, the function will have a prototype attribute,
This attribute points to the prototype object created through the constructor! Student.prototype
03. A prototype object is an object in memory that provides shared properties and methods for other objects!
04.The prototype attribute is only available to functions!
05. Each object has a__proto__
attribute, which points to the prototype object!
01. The prototype attribute is only available to functions!
02. Each object has a__proto__
attribute, which points to the prototype object!
Prototype chain:
01. A prototype object is an instance of another prototype object! A kitten is an example of an animal!
02. The related prototype chains progress layer by layer, forming a chain of instances and prototype objects. We call it the prototype chain!
The black cat squatting in the corner (example)
inherit
Cat class (01. Equivalent to a black cat, it is a prototype object 02. Compared to an animal, it is an instance)
inherit
Animal class (01. Prototype object of all animals 02. Instance of object)
inherit
Object (the top level of all prototype objects)
As long as it is an object, it has the__proto__
attribute, pointing to the prototype object!
question:
Object is an object!
It has__proto__
attribute!
The attribute value is null!
Combined inheritance:
Sometimes called pseudo-classical inheritance, it combines the techniques of prototype chaining and borrowing constructors,
An inheritance pattern that leverages the best of both worlds uses the prototype chain to inherit prototype properties and methods.
Inheriting instance attributes is achieved by borrowing constructors
Related recommendations:
Detailed explanation of js object-oriented inheritance knowledge
Detailed description of JS object-oriented programming
JavaScript object-oriented design_js object-oriented
The above is the detailed content of JS object-oriented usage examples. For more information, please follow other related articles on the PHP Chinese website!