Home  >  Article  >  Web Front-end  >  Attribute analysis of Boolean objects in JavaScript_Basic knowledge

Attribute analysis of Boolean objects in JavaScript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:35:431036browse

constructor attribute

Example
Returns a function created from the prototype of a myvar object:

var myvar = new Boolean(1);
myvar.constructor;


Result output:

function Boolean() { [native code] }

Definition and usage
The constructor property returns a reference to the Boolean function that created this object.


prototype constructor
Create a new method for Boolean objects:

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 Result output:

green

Definition and usage
The prototype property gives you the ability to add properties and methods to an object.
When constructing a prototype, all Boolean objects have properties or methods added by default.
Note: Prototype is a global property for almost all JavaScript objects.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn