prototype (Array - JavaScript)
Extends the object with additional properties and methods.
Defined in
Array (Standard - JavaScript)Syntax
prototype.name = value
Return value | Description |
---|---|
name |
The name of the property or method. |
value |
The value of the property or method. For a property, this should be an expression. For a method, this should be a function definition. |
Examples
(1) This computed label defines a property for the Array object then displays it.Array.prototype.coname = ["Acme Corporation", "Chicago"];
Array.coname[0] + ", " + Array.coname[1]
(2) This computed
label defines a function for the Array object then calls it.
Array.prototype.toProper = function() {
for(var i=0; i<this.length; i++) {
this[i] = this[i].left(1).toUpper() + this[i].substr(1).toLower();
}
return this;
}
var a = new Array("one", "two", "three", "four");
a.toProper() // [One, Two, Three, Four]