Attribute parsing of Boolean objects in JavaScript _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the property parsing of Boolean objects in JavaScript, including a brief introduction to the constructor attributes and prototype constructor constructors. For more information, see Constructor attributes

Instance
Returns the function created using the prototype of the myvar object:

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


Result output:

function Boolean() { [native code] }

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


Prototype Constructor
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 result output:

green

Definition and usage
The prototype attribute enables you to add attributes and methods to an object.
When constructing a prototype, all Boolean objects are added with properties or methods by default.
Note: Prototype is a global attribute, which is applicable to almost all JavaScript objects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.