JavaScript Boolean prototypeConstructor

Boolean 对象参考手册JavaScript Boolean Object

Instance

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;

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the prototype property.


Syntax

Boolean.prototype.name=value


Boolean 对象参考手册JavaScript Boolean Object

Other Extensions