English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeLe proprietà ti permettono di aggiungere proprietà e metodi ai tuoi oggetti String.
Attenzione:prototype è una proprietà globale disponibile praticamente per tutti gli oggetti (Number, Array, String e Date, ecc.).
String.prototype.name = value
Crea un nuovo metodo di stringa che restituisce il numero di vocali nel testo fornito:
String.prototype.countVowels = function() { var x = this.match(/[aeiou]/gi); return (x === null ? 0 : x.length); };
Usa nuovi metodi sulle stringhe:
var str = 'Hello world'; str.countVowels(); // return 3
Tutti i browser supportano completamente la proprietà prototype:
Proprietà | |||||
prototype | Sì | Sì | Sì | Sì | Sì |