mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-16 07:51:52 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -49,7 +49,7 @@
|
||||
<p>逻辑规则保证这些评估总是正确的。请注意,上述表达式中的 anything 部分未被评估,因此这样做的任何副作用都不会生效。还要注意,上述表达式的 anything 部分是任何单个逻辑表达式(如圆括号所示)。</p>
|
||||
<p>例如,下面示例代码中的两个函数是相等的。</p>
|
||||
<p>Short circuit means that the <em>expr</em> parts above are <strong>not evaluated</strong>, hence any side effects of doing so do not take effect (e.g., if <em>expr</em> is a function call, the calling never takes place). This happens because the value of the operator is already determined after the evaluation of the first operand. See example:</p>
|
||||
<pre class="brush: js">function A(){ console.log('called A'); return false; }
|
||||
<pre><code class="language-javascript">function A(){ console.log('called A'); return false; }
|
||||
function B(){ console.log('called B'); return true; }
|
||||
|
||||
console.log( A() && B() );
|
||||
@@ -59,15 +59,15 @@ console.log( A() && B() );
|
||||
console.log( B() || A() );
|
||||
// logs "called B" due to the function call,
|
||||
// then logs true (which is the resulting value of the operator)
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="Operators_precedence">Operators precedence</h3>
|
||||
<p>请注意,由于<a href="Reference/Operators/Operator_Precedence">运算符优先级</a>的存在,下面的表达式的结果却不相同。右侧被小括号括起来的操作变成了独立的表达式。</p>
|
||||
<pre class="brush: js">false && true || true // 结果为 true
|
||||
<pre><code class="language-javascript">false && true || true // 结果为 true
|
||||
false && (true || true) // 结果为 false
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="逻辑与()">逻辑与(<code>&&</code>)</h3>
|
||||
<p>下面的代码是 && (逻辑与) 运算符的示例.</p>
|
||||
<pre class="brush: js">a1 = true && true // t && t 返回 true
|
||||
<pre><code class="language-javascript">a1 = true && true // t && t 返回 true
|
||||
a2 = true && false // t && f 返回 false
|
||||
a3 = false && true // f && t 返回 false
|
||||
a4 = false && (3 == 4) // f && f 返回 false
|
||||
@@ -76,10 +76,10 @@ a6 = false && "Cat" // f && t 返回 false
|
||||
a7 = "Cat" && false // t && f 返回 false
|
||||
a8 = '' && false // f && f 返回 ""
|
||||
a9 = false && '' // f && f 返回 false
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="逻辑或()">逻辑或(<code>||</code>)</h3>
|
||||
<p>下面的代码是 || (逻辑或) 运算符的示例。</p>
|
||||
<pre class="brush: js">o1 = true || true // t || t 返回 true
|
||||
<pre><code class="language-javascript">o1 = true || true // t || t 返回 true
|
||||
o2 = false || true // f || t 返回 true
|
||||
o3 = true || false // t || f 返回 true
|
||||
o4 = false || (3 == 4) // f || f 返回 false
|
||||
@@ -88,47 +88,47 @@ o6 = false || "Cat" // f || t 返回 "Cat"
|
||||
o7 = "Cat" || false // t || f 返回 "Cat"
|
||||
o8 = '' || false // f || f 返回 false
|
||||
o9 = false || '' // f || f 返回 ""
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="逻辑非(!)">逻辑非(<code>!</code>)</h3>
|
||||
<p>下面的代码是 <code>!</code> (逻辑非) 运算符的示例.</p>
|
||||
<pre class="brush: js">n1 = !true // !t 返回 false
|
||||
<pre><code class="language-javascript">n1 = !true // !t 返回 false
|
||||
n2 = !false // !f 返回 true
|
||||
n3 = !'' // !f 返回 true
|
||||
n4 = !'Cat' // !t 返回 false
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="双重非(!!)运算符">双重非(<code>!!</code>)运算符</h4>
|
||||
<p>It is possible to use a couple of NOT operators in series to explicitly force the conversion of any value to the corresponding <a href="/en-US/docs/Web/JavaScript/Data_structures#Boolean_type">boolean primitive</a>. The conversion is based on the "truthyness" or "falsyness" of the value (see <a class="glossaryLink" href="/en-US/docs/Glossary/truthy" title='truthy: In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, "", null, undefined, and NaN).'>truthy</a> and <a class="glossaryLink" href="/en-US/docs/Glossary/falsy" title="falsy: A falsy value is a value that is considered false when encountered in a Boolean context.">falsy</a>).</p>
|
||||
<p>The same conversion can be done through the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> function.</p>
|
||||
<pre class="brush: js syntaxbox">n1 = !!true // !!truthy 返回 true
|
||||
<pre><code class="language-js syntaxbox">n1 = !!true // !!truthy 返回 true
|
||||
n2 = !!{} // !!truthy 返回 true: <strong>任何</strong> 对象都是 truthy 的…
|
||||
n3 = !!(new Boolean(false)) // …甚至 <em>.valueOf()</em> 返回 false 的布尔值对象也是!
|
||||
n4 = !!false // !!falsy 返回 false
|
||||
n5 = !!"" // !!falsy 返回 false
|
||||
n6 = !!Boolean(false) // !!falsy 返回 false
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="布尔值转换规则">布尔值转换规则</h3>
|
||||
<h4 id="将_AND_转换为_OR">将 AND 转换为 OR</h4>
|
||||
<p>以下涉及<strong>布尔</strong>运算的操作:</p>
|
||||
<pre class="brush: js">bCondition1 && bCondition2</pre>
|
||||
<pre><code class="language-javascript">bCondition1 && bCondition2</code></pre>
|
||||
<p>总是等于:</p>
|
||||
<pre class="brush: js">!(!bCondition1 || !bCondition2)</pre>
|
||||
<pre><code class="language-javascript">!(!bCondition1 || !bCondition2)</code></pre>
|
||||
<h4 id="将_OR_转换为_AND">将 OR 转换为 AND</h4>
|
||||
<p>以下涉及<strong>布尔</strong>运算的操作:</p>
|
||||
<pre class="brush: js">bCondition1 || bCondition2</pre>
|
||||
<pre><code class="language-javascript">bCondition1 || bCondition2</code></pre>
|
||||
<p>总是等于:</p>
|
||||
<pre class="brush: js">!(!bCondition1 && !bCondition2)</pre>
|
||||
<pre><code class="language-javascript">!(!bCondition1 && !bCondition2)</code></pre>
|
||||
<h3 id="删除嵌套的小括号">删除嵌套的小括号</h3>
|
||||
<p>由于逻辑表达式是从左往右计算的,所以,通常可以按照下面的规则删除小括号。</p>
|
||||
<h4 id="删除嵌套的_AND">删除嵌套的 AND</h4>
|
||||
<p>以下涉及<strong>布尔</strong>运算的操作:</p>
|
||||
<pre class="brush: js">bCondition1 || (bCondition2 && bCondition3)</pre>
|
||||
<pre><code class="language-javascript">bCondition1 || (bCondition2 && bCondition3)</code></pre>
|
||||
<p>总是等于:</p>
|
||||
<pre class="brush: js">bCondition1 || bCondition2 && bCondition3</pre>
|
||||
<pre><code class="language-javascript">bCondition1 || bCondition2 && bCondition3</code></pre>
|
||||
<h4 id="删除嵌套的_OR">删除嵌套的 OR</h4>
|
||||
<p>以下涉及<strong>布尔</strong>运算的操作:</p>
|
||||
<pre class="brush: js">bCondition1 && (bCondition2 || bCondition3)</pre>
|
||||
<pre><code class="language-javascript">bCondition1 && (bCondition2 || bCondition3)</code></pre>
|
||||
<p>总是等于:</p>
|
||||
<pre class="brush: js">!(!bCondition1 || !bCondition2 && !bCondition3)</pre>
|
||||
<pre><code class="language-javascript">!(!bCondition1 || !bCondition2 && !bCondition3)</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user