Some examples of methods and attributes inherited in JavaScript can be referenced.
Role of the prototype attribute:
The prototype attribute provides a set of basic functions of the object class. The new instance of the object "inherits" the operation that is granted to the object prototype.
Features of the prototype attribute:
All JavaScript internal objects have the read-only prototype attribute. You can add a function for the internal object prototype, but the object cannot be assigned a different prototype.
However, user-defined objects can be assigned to new prototypes.
Role of the constructor attribute:
Constructor indicates the function used to create an object.
Functions of the constructor attribute:
The constructor attribute is a member of all objects with prototype. They include all JavaScript internal objects except Global and Math objects.
The constructor attribute stores references to the functions used to construct a specific object instance.
A. Use prototype to add object attributes [method 1]
Example:
The Code is as follows: