| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
prototype Property (Object) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
9fc434a1-5995-4fcb-a4e8-00e7f615aaa2 |
11 |
mikejo5000 |
mikejo |
ghogen |
Returns a reference to the prototype for a class of objects.
objectName.prototype
The objectName argument is the name of an object.
Use the prototype property to provide a base set of functionality to a class of objects. New instances of an object "inherit" the behavior of the prototype assigned to that object.
For example, to add a method to the Array object that returns the value of the largest element of the array, declare the function, add it to Array.prototype, and then use it.
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 myArray = new Array(7, 1, 3, 11, 25, 9
);
document.write(myArray.max());
// Output:
// 25
All intrinsic [!INCLUDEjavascript] objects have a prototype property that is read-only. Properties and methods may be added to the prototype, but the object may not be assigned a different prototype. However, user-defined objects may be assigned a new prototype.
The method and property lists for each intrinsic object in this language reference indicate which ones are part of the object's prototype, and which are not.
[!INCLUDEjsv2]