Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Boolean prototype constructor

JavaScript Boolean prototype constructor

Boolean Object Reference JavaScript Boolean object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the prototype property.


Syntax

Boolean.prototype.

name

=

value


Boolean Object Reference JavaScript Boolean object