mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-15 23:37:25 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<p></p><p></p>
|
||||
<p><strong><code>Boolean</code></strong>对象是一个布尔值的对象包装器。</p>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox">new Boolean([<var>value</var>])</pre>
|
||||
<pre><code class="language-javascript">new Boolean([<var>value</var>])</code></pre>
|
||||
<h3 id="参数">参数</h3>
|
||||
<dl>
|
||||
<dt><code>value</code></dt>
|
||||
@@ -12,27 +12,27 @@
|
||||
<p>如果第一个参数不是布尔值,则会将其转换为布尔值。如果省略该参数,或者其值为 <code>0</code>、<code>-0</code>、<a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a>、<code>false</code>、<a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字(Not-A-Number)。"><code>NaN</code></a>、<a href="Reference/Global_Objects/undefined" title="undefined是全局对象的一个属性。也就是说,它是全局作用域的一个变量。undefined的最初值就是原始数据类型undefined。"><code>undefined</code></a>、或者空字符串(<code>""</code>),则生成的 <code>Boolean</code> 对象的值为 <code>false</code>。如果传入的参数是 DOM 对象 <a href="/zh-CN/docs/Web/API/Document/all" title="The Document interface's read-only all property returns an HTMLAllCollection rooted at the document node. In other words, it returns the entire contents of the page."><code>document.all</code></a>,也会生成值为 <code>false</code> 的 <code>Boolean</code> 对象。任何其他的值,包括值为 <code>"false"</code> 的字符串和任何对象,都会创建一个值为 <code>true</code> 的 <code>Boolean</code> 对象。</p>
|
||||
<p>注意不要将基本类型中的布尔值 <code>true</code> 和 <code>false</code> 与值为 <code>true</code> 和 <code>false</code> 的 <code>Boolean</code> 对象弄混了。</p>
|
||||
<p>当 <code>Boolean</code> 对象用于条件语句的时候(译注:意为直接应用于条件语句),任何不是 <a href="Reference/Global_Objects/undefined" title="undefined是全局对象的一个属性。也就是说,它是全局作用域的一个变量。undefined的最初值就是原始数据类型undefined。"><code>undefined</code></a> 和 <a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a> 的对象,包括值为 <code>false</code> 的 <code>Boolean</code> 对象,都会被当做 <code>true</code> 来对待。例如,下面 <a href="Reference/Statements/if...else" title="当指定条件为真,if 语句会执行一段语句。如果条件为假,则执行另一段语句。"><code>if</code></a> 语句中的条件为真:</p>
|
||||
<pre class="brush: js">var x = new Boolean(false);
|
||||
<pre><code class="language-javascript">var x = new Boolean(false);
|
||||
if (x) {
|
||||
// 这里的代码会被执行
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>基本类型的布尔值不受此规则影响。例如下面的 <a href="Reference/Statements/if...else" title="当指定条件为真,if 语句会执行一段语句。如果条件为假,则执行另一段语句。"><code>if</code></a> 语句的条件为假:</p>
|
||||
<pre class="brush: js">var x = false;
|
||||
<pre><code class="language-javascript">var x = false;
|
||||
if (x) {
|
||||
// 这里的代码不会执行
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>不要用创建 <code>Boolean</code> 对象的方式将一个非布尔值转化成布尔值,直接将 <code>Boolean</code> 当做转换函数来使用即可:</p>
|
||||
<pre class="brush: js">var x = Boolean(expression); // 推荐
|
||||
<pre><code class="language-javascript">var x = Boolean(expression); // 推荐
|
||||
var x = new Boolean(expression); // 不太好
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>对于任何对象,即使是值为 <code>false</code> 的 <code>Boolean</code> 对象,当将其传给 <code>Boolean</code> 函数时,生成的 <code>Boolean</code> 对象的值都是 <code>true</code>。</p>
|
||||
<pre class="brush: js">var myFalse = new Boolean(false); // false
|
||||
<pre><code class="language-javascript">var myFalse = new Boolean(false); // false
|
||||
var g = new Boolean(myFalse); // true
|
||||
var myString = new String("Hello");
|
||||
var s = new Boolean(myString); // true
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>最后,不要在应该使用基本类型布尔值的地方使用 <code>Boolean</code> 对象。</p>
|
||||
<h2 id="Properties" name="Properties">属性</h2>
|
||||
<dl>
|
||||
@@ -61,20 +61,20 @@ var s = new Boolean(myString); // true
|
||||
</dl></div>
|
||||
<h2 id="Examples" name="Examples">示例</h2>
|
||||
<h3 id="Creating_Boolean_objects_with_an_initial_value_of_false" name="Creating_Boolean_objects_with_an_initial_value_of_false">创建值为 <code>false</code> 的 <code>Boolean</code> 对象</h3>
|
||||
<pre class="brush: js">var bNoParam = new Boolean();
|
||||
<pre><code class="language-javascript">var bNoParam = new Boolean();
|
||||
var bZero = new Boolean(0);
|
||||
var bNull = new Boolean(null);
|
||||
var bEmptyString = new Boolean('');
|
||||
var bfalse = new Boolean(false);
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="Creating_Boolean_objects_with_an_initial_value_of_false" name="Creating_Boolean_objects_with_an_initial_value_of_false">创建值为 <code>true</code> 的 <code>Boolean</code> 对象</h3>
|
||||
<pre class="brush: js">var btrue = new Boolean(true);
|
||||
<pre><code class="language-javascript">var btrue = new Boolean(true);
|
||||
var btrueString = new Boolean('true');
|
||||
var bfalseString = new Boolean('false');
|
||||
var bSuLin = new Boolean('Su Lin');
|
||||
var bArrayProto = new Boolean([]);
|
||||
var bObjProto = new Boolean({});
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user