SoFunction
Updated on 2025-04-14

Description of prototype js class

The following is the explanation about prototype:

=====
constructor attribute

Applied to: Array object | Boolean object | Date object | Function object | Number object | Object object | String object
Require
Version 2
Returns a reference to the object type prototype.


The objectName parameter is the name of the object.

illustrate
Use the prototype attribute to provide a set of basic functions of the object's class. A new instance of an object "inherits" the operation that gives the object prototype.

For example, to add a method to the Array object that returns the maximum element value in the array. To accomplish this, declare the function, join it, and use it.

function array_max( ){
   var i, max = this[0];
   for (i = 1; i < ; i++)
   {
   if (max < this[i])
   max = this[i];
   }
   return max;
}
 = array_max;
var x = new Array(1, 2, 3, 4, 5, 6);
var y = ( );
After this code is executed, y saves the maximum value in the array x, or 6.

All JScript internal objects have read-only prototype properties. Functions can be added to the prototype as in this example, but the object cannot be assigned to a different prototype. However, user-defined objects can be assigned to new prototypes.

The method and property list of each internal object in this language reference points out which are part of the object prototype and which are not.