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

Attribute analysis of Boolean objects in JavaScript_Basic knowledge

WBOY
Release: 2016-05-16 15:35:43
Original
1066 people have browsed it

constructor attribute

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

var myvar = new Boolean(1);
myvar.constructor;
Copy after login


Result output:

function Boolean() { [native code] }
Copy after login

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";
 }
}
Copy after login

Create a Boolean object and add the myColor method:

var a=new Boolean(1);
a.myColor();
var b=a.color;
Copy after login


b Result output:

green
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template