JavaScript Boolean prototype constructor
Example
Create a new method for the Boolean object:
Boolean.prototype.myColor=function()
{
if (this.valueOf()==true)
{
this.color="green";
}
else
{
this.color="red";
}
}
Create a Boolean object and add the myColor method:
var a=new Boolean(1);
a.myColor();
var b=a.color;
b Output result:
green
Try it »
Definition and Usage
The prototype property allows you to add properties and methods to an object.
When a prototype is constructed, all Boolean objects have the property or method added by default.
Note: Boolean.prototype does not reference a boolean value, but the Boolean() object does.
Note: Prototype is a global property applicable to nearly all JavaScript objects.
Browser support





All major browsers support the prototype property.
Syntax
Boolean.prototype.
name
=
value
JavaScript Boolean object