Document: prototype attributes
Returns a reference to an object type prototype.
ObjectName. prototype
The objectName parameter is the object name.
Description
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.
For example, you want to add a method to the Array object to return the maximum element value in the Array. To accomplish this, declare the function, add it to Array. prototype, and use it.
Copy codeThe Code is as follows:
Function array_max (){
Var I, max = this [0];
For (I = 1; I <this. length; I ++)
{
If (max <this [I])
Max = this [I];
}
Return max;
}
Array. prototype. max = array_max;
Var x = new Array (1, 2, 3, 4, 5, 6 );
Var y = x. max ();
After the code is executed, y saves the maximum value in array x, or 6.
All internal JScript objects have the read-only prototype attribute. You can add features for the prototype as in this example, but the object cannot be assigned different prototypes. However, user-defined objects can be assigned to new prototypes.
The method and attribute list of each internal object in this language reference specifies which parts of the object prototype and which parts are not.