English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeProperties allow you to add properties and methods to the Boolean() object.
Note:prototype is a global property that is available for almost all objects (numbers, arrays, strings, dates, and so on).
Boolean.prototype.name = value
Create a new boolean method to change the paragraph's background:
Boolean.prototype.isEven = function() { if (this.valueOf() == true) { return "lightgreen"; } else { return "red"; } };
Then create a boolean value and call the isEven() method:
function myFunc() { var a = true; document.getElementById('result').style.background = a.isEven(); }
All browsers fully support the prototype property:
Properties | |||||
prototype | Yes | Yes | Yes | Yes | Yes |