Javascript Reference
Categories: Array

javascript Array prototype

@March 15, 2008, 1:22 a.m.
prototype Firefox/Netscape/NN 3 IE 4 ECMA 1  

Read/Write  

This is a property of the static Array object. Use the prototype property to assign new properties and methods to future instances of arrays created in the current document. For example, the following function creates a return-delimited list of elements in an array in reverse order:

function formatAsList( ) {
    var output = "";
    for (var i = this.length - 1; i>= 0; i--) {
        output += this[i] + "\n";
    }
    alert(output);
} 
 

To give an array that power, assign this function reference to a prototype property whose name you want to use as the method to invoke this function:

Array.prototype.showReverseList = formatAsList;
 

If a script creates an array at this point:

var stooges = new Array("Moe", "Larry", "Curly", "Shemp");

the new array has the showReverseList( ) method available to it. To invoke the method, the call is:

stooges.showReverseList( );
 

You can add properties the same way. These allow you to attach information about the array (its creation time, for example) without disturbing the ordered sequence of array data. When a new document loads into the window or frame, the static Array object starts fresh again.

 
Example
 
Array.prototype.created = "";
 
Value

Any data, including function references.

buy lipitor 40mg online cheap <a href="https://lipiws.top/">atorvastatin 10mg usa</a> order atorvastatin without prescription
Gojnqy - 9 months
cheap lipitor 80mg <a href="https://lipiws.top/">buy atorvastatin 20mg online cheap</a> atorvastatin 40mg generic
Vpomcg - 9 months

Powered by Linode.