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.