English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeProperties allow you to add properties and methods to the String object.
Note:Prototype is a global property that is available for almost all objects (Number, Array, String, and Date, etc.).
String.prototype.name = value
Create a new string method that returns the number of vowels in the given text:
String.prototype.countVowels = function() { var x = this.match(/[aeiou]/gi); return (x === null ? 0 : x.length); };
Using new methods on strings:
var str = 'Hello world'; str.countVowels(); // return 3
All browsers fully support the prototype property:
Properties | |||||
prototype | Yes | Yes | Yes | Yes | Yes |