English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeLe proprietà ti permettono di aggiungere attributi e metodi agli oggetti Boolean()
Attenzione:prototype è una proprietà globale, quasi tutti gli oggetti (numeri, array, stringhe, date ecc.) possono utilizzarla.
Boolean.prototype.name = value
Crea un nuovo metodo booleano per cambiare lo sfondo del paragrafo:
Boolean.prototype.isEven = function() { if (this.valueOf() == true) { return "lightgreen"; } else { return "red"; } };
Poi crea un valore booleano e chiama il metodo isEven():
function myFunc() { var a = true; document.getElementById('result').style.background = a.isEven(); }
Tutti i browser supportano completamente la proprietà prototype:
Proprietà | |||||
prototype | Sì | Sì | Sì | Sì | Sì |