JavaScript Boolean prototypeConstructor
Instance
Create a new method for the Boolean object:
Boolean.prototype.myColor=function()
{
if (this.valueOf()==true)
{
this.color="green";
}
else
{
this.color="red";
}
}
{
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;
a.myColor();
var b=a.color;
bOutput result:
green
Try it Yourself »
Definition and Usage
The prototype property allows you to add properties and methods to objects.
When constructing a prototype, all Boolean objects have the properties or methods added by default.
Note:Boolean.prototype is not a reference to a Boolean value, but the Boolean() object is.
Note:Prototype is a global property that is available to almost all JavaScript objects.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the prototype property.
Syntax
Boolean.prototype.name=value
Other Extensions
JavaScript Boolean Object