mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-15 15:20:30 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -82,25 +82,25 @@
|
||||
<h2 id="赋值"><a name="Assignment">赋值</a></h2>
|
||||
<p>简单的赋值运算符,把一个值赋给一个变量。为了把一个值赋给多个变量,可以以链式使用赋值运算符。参考下例:</p>
|
||||
<h4 id="语法">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x = y
|
||||
</pre>
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x = y
|
||||
</code></pre>
|
||||
<h4 id="示例">示例</h4>
|
||||
<pre class="brush: js">// Assuming the following variables
|
||||
<pre><code class="language-javascript">// Assuming the following variables
|
||||
// x = 5
|
||||
// y = 10
|
||||
// z = 25
|
||||
|
||||
x = y // x is 10
|
||||
x = y = z // x, y and z are all 25
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="加赋值(Addition_assignment)"><a name="Addition_assignment">加赋值(Addition assignment)</a></h3>
|
||||
<p>加赋值运算符把一个右值与一个变量相加,然后把相加的结果赋给该变量。两个操作数的类型决定了加赋值运算符的行为。算术相加或字符串连接都有可能。更多细节参考 <a href="Reference/Operators/Arithmetic_Operators#Addition" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">addition operator</a>。</p>
|
||||
<h4 id="语法_2">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x += y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x += y
|
||||
<strong>Meaning:</strong> x = x + y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_2">示例</h4>
|
||||
<pre class="brush: js">// 定义下列变量
|
||||
<pre><code class="language-javascript">// 定义下列变量
|
||||
// foo = 'foo'
|
||||
// bar = 5
|
||||
// baz = true
|
||||
@@ -123,154 +123,154 @@ foo += false // "foofalse"
|
||||
|
||||
// String + String -> concatenation
|
||||
foo += 'bar' // "foobar"
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="减赋值(Subtraction_assignment)"><a name="Subtraction_assignment">减赋值(Subtraction assignment)</a></h3>
|
||||
<p>减赋值运算符使一个变量减去右值,然后把结果赋给该变量。更多细节查看 <a href="Reference/Operators/Arithmetic_Operators#Subtraction" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">subtraction operator</a> 。</p>
|
||||
<h4 id="语法_3">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x -= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x -= y
|
||||
<strong>Meaning:</strong> x = x - y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_3">示例</h4>
|
||||
<pre class="brush: js">// 假定已定义了下面的变量
|
||||
<pre><code class="language-javascript">// 假定已定义了下面的变量
|
||||
// bar = 5
|
||||
|
||||
bar -= 2 // 3
|
||||
bar -= "foo" // NaN
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="乘赋值(Multiplication_assignment)"><a name="Multiplication_assignment">乘赋值(Multiplication assignment)</a></h3>
|
||||
<p>乘赋值运算符使一个变量乘以右值,然后把相成的结果赋给该变量。更多细节查看 <a href="Reference/Operators/Arithmetic_Operators#Multiplication" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">multiplication operator</a>。</p>
|
||||
<h4 id="语法_4">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x *= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x *= y
|
||||
<strong>Meaning:</strong> x = x * y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_4">示例</h4>
|
||||
<pre class="brush: js">// 假定已定义了下面的变量
|
||||
<pre><code class="language-javascript">// 假定已定义了下面的变量
|
||||
// bar = 5
|
||||
|
||||
bar *= 2 // 10
|
||||
bar *= 'foo' // NaN
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="除赋值(Division_assignment)"><a name="Division_assignment">除赋值(Division assignment)</a></h3>
|
||||
<p>除赋值运算符使一个变量除以右值,然后把结果赋给该变量。更多细节查看 <a href="Reference/Operators/Arithmetic_Operators#Division" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">division operator</a>。</p>
|
||||
<h4 id="语法_5">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x /= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x /= y
|
||||
<strong>Meaning:</strong> x = x / y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_5">示例</h4>
|
||||
<pre class="brush: js">// 假定已定义了下面的变量
|
||||
<pre><code class="language-javascript">// 假定已定义了下面的变量
|
||||
// bar = 5
|
||||
|
||||
bar /= 2 // 2.5
|
||||
bar /= "foo" // NaN
|
||||
bar /= 0 // Infinity
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="模赋值(Remainder_assignment)"><a name="Remainder_assignment">模赋值(Remainder assignment)</a></h3>
|
||||
<p>模赋值运算符使一个变量除以右值,然后把余数赋给该变量。更多细节查看 <a href="Reference/Operators/Arithmetic_Operators#Remainder" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">remainder operator</a>。</p>
|
||||
<h4 id="语法_6">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x %= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x %= y
|
||||
<strong>Meaning:</strong> x = x % y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_6">示例</h4>
|
||||
<pre class="brush: js">// Assuming the following variable
|
||||
<pre><code class="language-javascript">// Assuming the following variable
|
||||
// bar = 5
|
||||
|
||||
bar %= 2 // 1
|
||||
bar %= 'foo' // NaN
|
||||
bar %= 0 // NaN
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="指数赋值(Exponentiation_assignment)"><a id="Exponentiation_assignment" name="Exponentiation_assignment">指数赋值(Exponentiation assignment)</a></h3>
|
||||
<p>指数赋值运算符使一个变量为底数、以右值为指数的指数运算(乘方)结果赋给该变量。更多细节查看 <a href="Reference/Operators/Arithmetic_Operators#Exponentiation" title="算术运算符以数值(字面量或变量)作为其操作数,并返回一个单个数值。标准算术运算符是加法(+),减法( - ),乘法(*)和除法(/)。">算术运算符</a>。</p>
|
||||
<h4 id="语法_7">语法</h4>
|
||||
<pre class="syntaxbox"><strong>语法:</strong> x **= y
|
||||
<pre><code class="language-javascript"><strong>语法:</strong> x **= y
|
||||
<strong>含义:</strong> x = x ** y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_7">示例</h4>
|
||||
<pre class="brush: js">// Assuming the following variable
|
||||
<pre><code class="language-javascript">// Assuming the following variable
|
||||
// bar = 5
|
||||
|
||||
bar **= 2 // 25
|
||||
bar **= 'foo' // NaN</pre>
|
||||
bar **= 'foo' // NaN</code></pre>
|
||||
<h3 id="左移赋值(Left_shift_assignment)"><a name="Left_shift_assignment">左移赋值(Left shift assignment)</a></h3>
|
||||
<p>左移赋值运算符使变量向左移动指定位数的比特位,然后把结果赋给该变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Left_shift" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。">left shift operator</a>。</p>
|
||||
<h4 id="语法_8">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x <<= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x <<= y
|
||||
<strong>Meaning:</strong> x = x << y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_8">示例</h4>
|
||||
<pre class="brush: js">var bar = 5; // (00000000000000000000000000000101)
|
||||
<pre><code class="language-javascript">var bar = 5; // (00000000000000000000000000000101)
|
||||
bar <<= 2; // 20 (00000000000000000000000000010100)
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="右移赋值(Right_shift_assignment)"><a name="Right_shift_assignment">右移赋值(Right shift assignment)</a></h3>
|
||||
<p>右移赋值运算符使变量向右移指定位数的比特位,然后把结果赋给该变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Right_shift" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。">right shift operator</a>。</p>
|
||||
<h4 id="语法_9">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x >>= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x >>= y
|
||||
<strong>Meaning:</strong> x = x >> y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_9">示例</h4>
|
||||
<pre class="brush: js">var bar = 5; // (00000000000000000000000000000101)
|
||||
<pre><code class="language-javascript">var bar = 5; // (00000000000000000000000000000101)
|
||||
bar >>= 2; // 1 (00000000000000000000000000000001)
|
||||
|
||||
var bar = -5; // (-00000000000000000000000000000101)
|
||||
bar >>= 2; // -2 (-00000000000000000000000000000010)
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="无符号右移赋值(Unsigned_right_shift_assignment)"><a name="Unsigned_right_shift_assignment">无符号右移赋值(Unsigned right shift assignment)</a></h3>
|
||||
<p>无符号右移赋值运算符向右移动指定数量的比特位,然后把结果赋给变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Unsigned_right_shift" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。"> unsigned right shift operator</a>。</p>
|
||||
<h4 id="语法_10">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x >>>= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x >>>= y
|
||||
<strong>Meaning:</strong> x = x >>> y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_10">示例</h4>
|
||||
<pre class="brush: js">var bar = 5; // (00000000000000000000000000000101)
|
||||
<pre><code class="language-javascript">var bar = 5; // (00000000000000000000000000000101)
|
||||
bar >>>= 2; // 1 (00000000000000000000000000000001)
|
||||
|
||||
var bar = -5; // (-00000000000000000000000000000101)
|
||||
bar >>>= 2; // 1073741822 (00111111111111111111111111111110)</pre>
|
||||
bar >>>= 2; // 1073741822 (00111111111111111111111111111110)</code></pre>
|
||||
<h3 id="按位与赋值(Bitwise_AND_assignment)"><a name="Bitwise_AND_assignment">按位与赋值(Bitwise AND assignment)</a></h3>
|
||||
<p>按位与赋值运算符使用两个操作值的二进制表示,执行按位与运算,并把结果赋给变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Bitwise_AND" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。">bitwise AND operator</a>。</p>
|
||||
<h4 id="语法_11">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x &= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x &= y
|
||||
<strong>Meaning:</strong> x = x & y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_11">示例</h4>
|
||||
<pre class="brush: js">var bar = 5;
|
||||
<pre><code class="language-javascript">var bar = 5;
|
||||
// 5: 00000000000000000000000000000101
|
||||
// 2: 00000000000000000000000000000010
|
||||
bar &= 2; // 0
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="按位异或赋值(Bitwise_XOR_assignment)"><a name="Bitwise_XOR_assignment">按位异或赋值(Bitwise XOR assignment)</a></h3>
|
||||
<p>按位异或赋值运算符使用两个操作值的二进制表示,执行二进制异或运算,并把结果赋给变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Bitwise_XOR" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。">bitwise XOR operator</a>。</p>
|
||||
<h4 id="语法_12">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x ^= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x ^= y
|
||||
<strong>Meaning:</strong> x = x ^ y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_12">示例</h4>
|
||||
<pre class="brush: js">var bar = 5;
|
||||
<pre><code class="language-javascript">var bar = 5;
|
||||
bar ^= 2; // 7
|
||||
// 5: 00000000000000000000000000000101
|
||||
// 2: 00000000000000000000000000000010
|
||||
// -----------------------------------
|
||||
// 7: 00000000000000000000000000000111
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="按位或赋值(Bitwise_OR_assignment)"><a name="Bitwise_OR_assignment">按位或赋值(Bitwise OR assignment)</a></h3>
|
||||
<p>按位或赋值运算符使用两个操作值的二进制表示,执行按位或运算,并把结果赋给变量。更多细节查看 <a href="Reference/Operators/Bitwise_Operators#Bitwise_OR" title="按位操作符(Bitwise operators) 将其操作数(operands)当作32位的比特序列(由0和1组成),而不是十进制、十六进制或八进制数值。例如,十进制数9,用二进制表示则为1001。按位操作符操作数字的二进制形式,但是返回值依然是标准的JavaScript数值。">bitwise OR operator</a>。</p>
|
||||
<h4 id="语法_13">语法</h4>
|
||||
<pre class="syntaxbox"><strong>Operator:</strong> x |= y
|
||||
<pre><code class="language-javascript"><strong>Operator:</strong> x |= y
|
||||
<strong>Meaning:</strong> x = x | y
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h4 id="示例_13">示例</h4>
|
||||
<pre class="brush: js">var bar = 5;
|
||||
<pre><code class="language-javascript">var bar = 5;
|
||||
bar |= 2; // 7
|
||||
// 5: 00000000000000000000000000000101
|
||||
// 2: 00000000000000000000000000000010
|
||||
// -----------------------------------
|
||||
// 7: 00000000000000000000000000000111
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="示例_14">示例</h2>
|
||||
<h3 id="带有赋值运算符的左值(Left_operand)">带有赋值运算符的左值(Left operand)</h3>
|
||||
<p>在某些不常见的情况下,赋值运算符(如<code> x += y</code>)并不等同于表达式(这是是 <code>x = x + y</code>)。当一个赋值运算符的左值包含有一个赋值运算符时,左值只会被求值一次。例如:</p>
|
||||
<pre class="brush: js">a[i++] += 5 // i 执行一次求值
|
||||
<pre><code class="language-javascript">a[i++] += 5 // i 执行一次求值
|
||||
a[i++] = a[i++] + 5 // i 执行两次求值
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user