Boolean.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  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; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Boolean'>/**
  19. </span> * @class Boolean
  20. *
  21. * The `Boolean` object is an object wrapper for a boolean value.
  22. *
  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 (&quot;&quot;), the object has an
  25. * initial value of false. All other values, including any object or the string `&quot;false&quot;`, create an
  26. * object with an initial value of true.
  27. *
  28. * Do not confuse the primitive Boolean values true and false with the true and false values of the
  29. * Boolean object.
  30. *
  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:
  34. *
  35. * x = new Boolean(false);
  36. * if (x) {
  37. * // . . . this code is executed
  38. * }
  39. *
  40. * This behavior does not apply to Boolean primitives. For example, the condition in the following if
  41. * statement evaluates to `false`:
  42. * x = false;
  43. * if (x) {
  44. * // . . . this code is not executed
  45. * }
  46. *
  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:
  49. *
  50. * x = Boolean(expression); // preferred
  51. * x = new Boolean(expression); // don't use
  52. *
  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.
  55. *
  56. * myFalse = new Boolean(false); // initial value of false
  57. * g = new Boolean(myFalse); // initial value of true
  58. * myString = new String(&quot;Hello&quot;); // string object
  59. * s = new Boolean(myString); // initial value of true
  60. *
  61. * Do not use a Boolean object in place of a Boolean primitive.
  62. *
  63. * # Creating Boolean objects with an initial value of false
  64. *
  65. * bNoParam = new Boolean();
  66. * bZero = new Boolean(0);
  67. * bNull = new Boolean(null);
  68. * bEmptyString = new Boolean(&quot;&quot;);
  69. * bfalse = new Boolean(false);
  70. *
  71. * # Creating Boolean objects with an initial value of true
  72. *
  73. * btrue = new Boolean(true);
  74. * btrueString = new Boolean(&quot;true&quot;);
  75. * bfalseString = new Boolean(&quot;false&quot;);
  76. * bSuLin = new Boolean(&quot;Su Lin&quot;);
  77. *
  78. * &lt;div class=&quot;notice&quot;&gt;
  79. * Documentation for this class comes from &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean&quot;&gt;MDN&lt;/a&gt;
  80. * and is available under &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/&quot;&gt;Creative Commons: Attribution-Sharealike license&lt;/a&gt;.
  81. * &lt;/div&gt;
  82. */
  83. <span id='Boolean-method-constructor'>/**
  84. </span> * @method constructor
  85. * Creates a new boolean object.
  86. * @param {Object} value Either a truthy or falsy value to create the corresponding Boolean object.
  87. */
  88. //Methods
  89. <span id='Boolean-method-toString'>/**
  90. </span> * @method toString
  91. * Returns a string of either &quot;true&quot; or &quot;false&quot; depending upon the value of the object.
  92. * Overrides the `Object.prototype.toString` method.
  93. *
  94. * The Boolean object overrides the `toString` method of the `Object` object; it does not inherit
  95. * `Object.toString`. For Boolean objects, the `toString` method returns a string representation of
  96. * the object.
  97. *
  98. * JavaScript calls the `toString` method automatically when a Boolean is to be represented as a text
  99. * value or when a Boolean is referred to in a string concatenation.
  100. *
  101. * For Boolean objects and values, the built-in `toString` method returns the string `&quot;true&quot;` or
  102. * `&quot;false&quot;` depending on the value of the boolean object. In the following code, `flag.toString`
  103. * returns `&quot;true&quot;`.
  104. *
  105. * var flag = new Boolean(true)
  106. * var myVar = flag.toString()
  107. *
  108. * @return {String} The boolean value represented as a string.
  109. */
  110. <span id='Boolean-method-valueOf'>/**
  111. </span> * @method valueOf
  112. * Returns the primitive value of the `Boolean` object. Overrides the `Object.prototype.valueOf` method.
  113. *
  114. * The `valueOf` method of Boolean returns the primitive value of a Boolean object or literal Boolean
  115. * as a Boolean data type.
  116. *
  117. * This method is usually called internally by JavaScript and not explicitly in code.
  118. *
  119. * x = new Boolean();
  120. * myVar = x.valueOf() //assigns false to myVar
  121. *
  122. * @return {Boolean} The primitive value.
  123. */</pre>
  124. </body>
  125. </html>