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.