
prototype属性允许您向Boolean()对象添加属性和方法。
注意:prototype是一个全局属性,几乎所有对象(数字,数组,字符串和日期等)都可用。
语法:
Boolean.prototype.name = value
创建一个新的布尔方法来更改段落的背景:
Boolean.prototype.isEven = function() {
if (this.valueOf() == true) {
return "lightgreen";
} else {
return "red";
}
};然后创建一个布尔值,并调用isEven()方法:
function myFunc() {
var a = true;
document.getElementById('result').style.background = a.isEven();
}浏览器兼容性
所有浏览器完全支持prototype属性:
| 属性 | ![]() | ![]() | ![]() | ![]() | ![]() |
| prototype | 是 | 是 | 是 | 是 | 是 |




