prototype (RegExp - JavaScript)

Extends the object with additional properties and methods.

Defined in

RegExp (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 field defines a property then uses it.
RegExp.prototype.sp3 = /(   )/g;

var cities = "Paris   Moscow   Tokyo";
RegExp.sp3.replace(cities, "-")
(2) This computed field defines a function then calls it.
RegExp.prototype.sp3replace = function(x) {
	return /(   )/g.replace(x, "-");
}

var cities = "Paris   Moscow   Tokyo";
requestScope.y = RegExp.sp3replace(cities)