4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Boolean'>/**
19 </span> * @class Boolean
21 * The `Boolean` object is an object wrapper for a boolean value.
23 * The value passed as the first parameter is converted to a boolean value, if necessary. If value is
24 * omitted or is 0, -0, null, false, `NaN`, undefined, or the empty string (""), the object has an
25 * initial value of false. All other values, including any object or the string `"false"`, create an
26 * object with an initial value of true.
28 * Do not confuse the primitive Boolean values true and false with the true and false values of the
31 * Any object whose value is not `undefined` or `null`, including a Boolean object whose value is false,
32 * evaluates to true when passed to a conditional statement. For example, the condition in the following
33 * if statement evaluates to true:
35 * x = new Boolean(false);
37 * // . . . this code is executed
40 * This behavior does not apply to Boolean primitives. For example, the condition in the following if
41 * statement evaluates to `false`:
44 * // . . . this code is not executed
47 * Do not use a `Boolean` object to convert a non-boolean value to a boolean value. Instead, use Boolean
48 * as a function to perform this task:
50 * x = Boolean(expression); // preferred
51 * x = new Boolean(expression); // don't use
53 * If you specify any object, including a Boolean object whose value is false, as the initial value of a
54 * Boolean object, the new Boolean object has a value of true.
56 * myFalse = new Boolean(false); // initial value of false
57 * g = new Boolean(myFalse); // initial value of true
58 * myString = new String("Hello"); // string object
59 * s = new Boolean(myString); // initial value of true
61 * Do not use a Boolean object in place of a Boolean primitive.
63 * # Creating Boolean objects with an initial value of false
65 * bNoParam = new Boolean();
66 * bZero = new Boolean(0);
67 * bNull = new Boolean(null);
68 * bEmptyString = new Boolean("");
69 * bfalse = new Boolean(false);
71 * # Creating Boolean objects with an initial value of true
73 * btrue = new Boolean(true);
74 * btrueString = new Boolean("true");
75 * bfalseString = new Boolean("false");
76 * bSuLin = new Boolean("Su Lin");
78 * <div class="notice">
79 * Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean">MDN</a>
80 * and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
84 <span id='Boolean-method-constructor'>/**
85 </span> * @method constructor
86 * Creates a new boolean object.
87 * @param {Object} value Either a truthy or falsy value to create the corresponding Boolean object.
92 <span id='Boolean-method-toString'>/**
93 </span> * @method toString
94 * Returns a string of either "true" or "false" depending upon the value of the object.
95 * Overrides the `Object.prototype.toString` method.
97 * The Boolean object overrides the `toString` method of the `Object` object; it does not inherit
98 * `Object.toString`. For Boolean objects, the `toString` method returns a string representation of
101 * JavaScript calls the `toString` method automatically when a Boolean is to be represented as a text
102 * value or when a Boolean is referred to in a string concatenation.
104 * For Boolean objects and values, the built-in `toString` method returns the string `"true"` or
105 * `"false"` depending on the value of the boolean object. In the following code, `flag.toString`
106 * returns `"true"`.
108 * var flag = new Boolean(true)
109 * var myVar = flag.toString()
111 * @return {String} The boolean value represented as a string.
114 <span id='Boolean-method-valueOf'>/**
115 </span> * @method valueOf
116 * Returns the primitive value of the `Boolean` object. Overrides the `Object.prototype.valueOf` method.
118 * The `valueOf` method of Boolean returns the primitive value of a Boolean object or literal Boolean
119 * as a Boolean data type.
121 * This method is usually called internally by JavaScript and not explicitly in code.
124 * myVar = x.valueOf() //assigns false to myVar
126 * @return {Boolean} The primitive value.