The initial value of the prototype of a Boolean object is the built-in Boolean prototype object.
The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // Define a function that extends the output capabilities of Boolean objects function yesNo() { if(this == true) { return "The switch is ON"; } else { return "The switch is OFF"; } } // Register the new function Boolean.prototype.yesNo = yesNo; // Create a Boolean object and test the Boolean.yesNo() method myBoolean = new Boolean(true); document.write(myBoolean.yesNo()); document.write("<BR>"); myBoolean = !myBoolean; document.write(myBoolean.yesNo()); document.write("<BR>"); </SCRIPT> </BODY> </HTML>
ECMA 262 edition 2 - section - 15.2.3.1
ECMA 262 edition 2 - section - 15.6.3.1
ECMA 262 edition 3 - section - 15.6.3.1
Prev | Home | Next |
Boolean.constructor | Up | Boolean.toSource() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |