Home > Article > Web Front-end > Detailed explanation of prototype prototype instances in js
In JavaScript, prototype is a very important piece of knowledge. Here, I will briefly introduce prototype. Prototype can be understood as prototype extension. It is oriented to an object, and its function is to expand the functions we need in the prototype chain.
For example, if there is an Array instance in js, then Array inherits from Array.prototype, which is the prototype chain of Array. Like all constructors, we can change the prototype object of the constructor to Make changes to all Array instances. For example, you can add new methods and properties to extend all Array objects.
For example, there are two attributes in the an object, namely a and b. Then if I want to add another attribute to the an object, I can use an.prototype.Attribute name="you "Required attribute content", the adding method is the same, an.prototype. Attribute name = function ({}), by the way, because function ({}) itself is an anonymous function, it can be replaced with an arrow function. That is, an.prototype.Attribute name=()=>{}. The arrow function itself is also an anonymous function. The details will be introduced in the next article.
So, to summarize, the object.prototype attribute represents the prototype of all object constructors and allows us to add properties and methods to all object objects.
Related recommendations:
String.prototype.formatHow to use string splicing
Detailed explanation of the usage of the Prototype attribute of js
Detailed explanation of the use of prototype in JavaScript
The above is the detailed content of Detailed explanation of prototype prototype instances in js. For more information, please follow other related articles on the PHP Chinese website!