Material: Prototype Property
Returns a reference to the object type prototype.
Objectname.prototype
The objectname parameter is the name of the object.
Description
Use the prototype property to provide a set of basic functions for the object's class. The operation of the new instance of the object, "inherit", gives the object a prototype.
For example, to add a method that returns the maximum element value in an array for the array object. To do this, declare the function, add it to the Array.prototype, and use it.
Copy Code code 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 executes, Y saves the maximum value in the array x, or says 6.
All JScript internal objects have read-only prototype properties. You can add functionality to the prototype as in this example, but the object cannot be given a different prototype. However, user-defined objects can be assigned to a new prototype.
The list of methods and attributes for each internal object in the language reference indicates which parts of the object's prototype and which are not.