English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeLas propiedades le permiten agregar atributos y métodos al objeto Boolean().
Atención:prototype es una propiedad global, disponible para casi todos los objetos (números, arreglos, cadenas y fechas, entre otros).
Boolean.prototype.name = value
Crea un nuevo método booleano para cambiar el fondo del párrafo:
Boolean.prototype.isEven = function() { if (this.valueOf() == true) { return "lightgreen"; } else { return "red"; } };
Luego crea un valor booleano y llama al método isEven():
function myFunc() { var a = true; document.getElementById('#)39;result#39;).style.background = a.isEven(); }
Todos los navegadores admiten completamente la propiedad prototype:
Atributos | |||||
prototype | Sí | Sí | Sí | Sí | Sí |