prototype (String - JavaScript)

Extends the object with additional properties and methods.

Defined in

String (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 String object then displays it.
String.prototype.coname = "Acme Corporation";

var s = new String();
s.coname
(2) This computed label defines a function for the String object then calls it.
String.prototype.toProper = function() {
	return this.left(1).toUpper() + this.substr(1).toLower();
}
var s = new String("bar");
s.toProper() // Bar