diff options
author | Irvin <irvinfly@gmail.com> | 2022-02-16 02:02:49 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 01b0e12ba27b5069248fd09235e9a7143915ee30 (patch) | |
tree | 0e9edf538dc3fa3331e1dbb79239b58186765f86 /files/zh-cn/web/javascript/reference/operators | |
parent | 6ca84f1794af830ada9736d7289ce29aabb04ca3 (diff) | |
download | translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.gz translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.bz2 translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.zip |
remove `notranslate` class in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/operators')
54 files changed, 289 insertions, 289 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/addition/index.html b/files/zh-cn/web/javascript/reference/operators/addition/index.html index c3726a9413..db323029cc 100644 --- a/files/zh-cn/web/javascript/reference/operators/addition/index.html +++ b/files/zh-cn/web/javascript/reference/operators/addition/index.html @@ -16,14 +16,14 @@ original_slug: Web/JavaScript/Reference/Operators/相加 <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>表达式:</strong> <var>x</var> + <var>y</var> +<pre class="syntaxbox"><strong>表达式:</strong> <var>x</var> + <var>y</var> </pre> <h2 id="示例">示例</h2> <h3 id="数字的相加运算">数字的相加运算</h3> -<pre class="brush: js notranslate">// Number + Number -> addition +<pre class="brush: js">// Number + Number -> addition 1 + 2 // 3 // Boolean + Number -> addition @@ -35,7 +35,7 @@ false + false // 0 <h3 id="字符串相加运算">字符串相加运算</h3> -<pre class="brush: js notranslate">// String + String -> concatenation +<pre class="brush: js">// String + String -> concatenation 'foo' + 'bar' // "foobar" // Number + String -> concatenation diff --git a/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html index 9469f0f0b7..5732d5c473 100644 --- a/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/addition_assignment/index.html @@ -17,14 +17,14 @@ translation_of: Web/JavaScript/Reference/Operators/Addition_assignment <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x += y +<pre class="syntaxbox"><strong>Operator:</strong> x += y <strong>Meaning:</strong> x = x + y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_addition_assignment">Using addition assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variables +<pre class="brush: js">// Assuming the following variables // foo = 'foo' // bar = 5 // baz = true diff --git a/files/zh-cn/web/javascript/reference/operators/assignment/index.html b/files/zh-cn/web/javascript/reference/operators/assignment/index.html index 8c981fe11e..b03fcf3224 100644 --- a/files/zh-cn/web/javascript/reference/operators/assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/assignment/index.html @@ -21,14 +21,14 @@ translation_of: Web/JavaScript/Reference/Operators/Assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x = y +<pre class="syntaxbox"><strong>Operator:</strong> x = y </pre> <h2 id="示例">示例</h2> <h3 id="简单赋值和链式赋值">简单赋值和链式赋值</h3> -<pre class="brush: js notranslate">// 假设已经存在以下变量 +<pre class="brush: js">// 假设已经存在以下变量 // x = 5 // y = 10 // z = 25 diff --git a/files/zh-cn/web/javascript/reference/operators/await/index.html b/files/zh-cn/web/javascript/reference/operators/await/index.html index 0183f4d7ae..8b07b23e41 100644 --- a/files/zh-cn/web/javascript/reference/operators/await/index.html +++ b/files/zh-cn/web/javascript/reference/operators/await/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Operators/await <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">[返回值] = await 表达式;</pre> +<pre class="syntaxbox">[返回值] = await 表达式;</pre> <dl> <dt>表达式</dt> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/await <p>如果一个 Promise 被传递给一个 await 操作符,await 将等待 Promise 正常处理完成并返回其处理结果。</p> -<pre class="brush: js notranslate">function resolveAfter2Seconds(x) { +<pre class="brush: js">function resolveAfter2Seconds(x) { return new Promise(resolve => { setTimeout(() => { resolve(x); @@ -56,7 +56,7 @@ f1(); <p>如果该值不是一个 Promise,await 会把该值转换为已正常处理的Promise,然后等待其处理结果。</p> -<pre class="brush: js notranslate">async function f2() { +<pre class="brush: js">async function f2() { var y = await 20; console.log(y); // 20 } @@ -65,7 +65,7 @@ f2(); <p>如果 Promise 处理异常,则异常值被抛出。</p> -<pre class="brush: js notranslate">async function f3() { +<pre class="brush: js">async function f3() { try { var z = await Promise.reject(30); } catch (e) { diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html index 9010ddf09b..c857ac2b41 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_and/index.html @@ -14,14 +14,14 @@ original_slug: Web/JavaScript/Reference/Operators/按位与 <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> & <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> & <var>b</var></code> </pre> <h2 id="描述">描述</h2> <p>操作数被转换为32位整数,并由一系列位(0和1)表示。 超过32位的数字将丢弃其最高有效位。 例如,以下大于32位的整数将被转换为32位整数:</p> -<pre class="brush: js notranslate">Before: 11100110111110100000000000000110000000000001 +<pre class="brush: js">Before: 11100110111110100000000000000110000000000001 After: 10100000000000000110000000000001</pre> <p>第一个操作数中的每个位都与第二个操作数中的相应位配对:第一位到第一位,第二位到第二位,依此类推。</p> @@ -62,7 +62,7 @@ After: 10100000000000000110000000000001</pre> </tbody> </table> -<pre class="brush: js notranslate">. 9 (base 10) = 00000000000000000000000000001001 (base 2) +<pre class="brush: js">. 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- 14 & 9 (base 10) = 00000000000000000000000000001000 (base 2) = 8 (base 10) @@ -74,7 +74,7 @@ After: 10100000000000000110000000000001</pre> <h3 id="使用按位与">使用按位与</h3> -<pre class="brush: js notranslate">// 5: 00000000000000000000000000000101 +<pre class="brush: js">// 5: 00000000000000000000000000000101 // 2: 00000000000000000000000000000010 5 & 2; // 0</pre> diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html index 5c92f0196c..05df4461d6 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_and_assignment/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x &= y +<pre class="syntaxbox"><strong>Operator:</strong> x &= y <strong>Meaning:</strong> x = x & y </pre> @@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment <h3 id="按位与赋值运算">按位与赋值运算</h3> -<pre class="brush: js notranslate">let a = 5; +<pre class="brush: js">let a = 5; // 5: 00000000000000000000000000000101 // 2: 00000000000000000000000000000010 a &= 2; // 0</pre> diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html index ff285826b0..416bb69347 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_not/index.html @@ -19,14 +19,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_NOT <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>~a</var></code> +<pre class="syntaxbox"><code><var>~a</var></code> </pre> <h2 id="描述">描述</h2> <p>操作数被转换为32位二进制表示(0和1)。超过32位的数字将丢弃其最高有效位。如下例子中,超过32位的整数转换为32位整数:</p> -<pre class="brush: js notranslate">Before: 11100110111110100000000000000110000000000001 +<pre class="brush: js">Before: 11100110111110100000000000000110000000000001 After: 10100000000000000110000000000001</pre> <p>第一个操作数中的每个位都与第二个操作数中的相应位配对:第一位到第一位,第二位到第二位,依此类推。</p> @@ -54,7 +54,7 @@ After: 10100000000000000110000000000001</pre> </tbody> </table> -<pre class="brush: js notranslate"> 9 (base 10) = 00000000000000000000000000001001 (base 2) +<pre class="brush: js"> 9 (base 10) = 00000000000000000000000000001001 (base 2) -------------------------------- ~9 (base 10) = 11111111111111111111111111110110 (base 2) = -10 (base 10) </pre> @@ -69,7 +69,7 @@ After: 10100000000000000110000000000001</pre> <h3 id="使用按位取反">使用按位取反</h3> -<pre class="brush: js notranslate">~0; // -1 +<pre class="brush: js">~0; // -1 ~-1; // 0 ~1; // -2 </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html index dcd9c54de0..245da8fdab 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> | <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> | <var>b</var></code> </pre> <h2 id="描述">描述</h2> <p>The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:</p> -<pre class="brush: js notranslate">Before: 11100110111110100000000000000110000000000001 +<pre class="brush: js">Before: 11100110111110100000000000000110000000000001 After: 10100000000000000110000000000001</pre> <p>Each bit in the first operand is paired with the corresponding bit in the second operand: <em>first bit</em> to <em>first bit</em>, <em>second bit</em> to <em>second bit</em>, and so on.</p> @@ -61,7 +61,7 @@ After: 10100000000000000110000000000001</pre> </tbody> </table> -<pre class="brush: js notranslate">. 9 (base 10) = 00000000000000000000000000001001 (base 2) +<pre class="brush: js">. 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- 14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10) @@ -73,7 +73,7 @@ After: 10100000000000000110000000000001</pre> <h3 id="Using_bitwise_OR">Using bitwise OR</h3> -<pre class="brush: js notranslate">// 9 (00000000000000000000000000001001) +<pre class="brush: js">// 9 (00000000000000000000000000001001) // 14 (00000000000000000000000000001110) 14 | 9; diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html index 752a80154a..fad4f94082 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_or_assignment/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x |= y +<pre class="syntaxbox"><strong>Operator:</strong> x |= y <strong>Meaning:</strong> x = x | y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_bitwise_OR_assignment">Using bitwise OR assignment</h3> -<pre class="brush: js notranslate">let a = 5; +<pre class="brush: js">let a = 5; a |= 2; // 7 // 5: 00000000000000000000000000000101 // 2: 00000000000000000000000000000010 diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html index c2fa597627..e68e1d436b 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_xor/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_XOR <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> ^ <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> ^ <var>b</var></code> </pre> <h2 id="描述">描述</h2> <p>The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:</p> -<pre class="brush: js notranslate">Before: 11100110111110100000000000000110000000000001 +<pre class="brush: js">Before: 11100110111110100000000000000110000000000001 After: 10100000000000000110000000000001</pre> <p>Each bit in the first operand is paired with the corresponding bit in the second operand: <em>first bit</em> to <em>first bit</em>, <em>second bit</em> to <em>second bit</em>, and so on.</p> @@ -61,7 +61,7 @@ After: 10100000000000000110000000000001</pre> </tbody> </table> -<pre class="brush: js notranslate">. 9 (base 10) = 00000000000000000000000000001001 (base 2) +<pre class="brush: js">. 9 (base 10) = 00000000000000000000000000001001 (base 2) 14 (base 10) = 00000000000000000000000000001110 (base 2) -------------------------------- 14 ^ 9 (base 10) = 00000000000000000000000000000111 (base 2) = 7 (base 10) @@ -73,7 +73,7 @@ After: 10100000000000000110000000000001</pre> <h3 id="Using_bitwise_XOR">Using bitwise XOR</h3> -<pre class="brush: js notranslate">// 9 (00000000000000000000000000001001) +<pre class="brush: js">// 9 (00000000000000000000000000001001) // 14 (00000000000000000000000000001110) 14 ^ 9; diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html index 7257e9cdb5..d8601d9eba 100644 --- a/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/bitwise_xor_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x ^= y +<pre class="syntaxbox"><strong>Operator:</strong> x ^= y <strong>Meaning:</strong> x = x ^ y</pre> <h2 id="例子">例子</h2> <h3 id="使用按位异或赋值">使用按位异或赋值</h3> -<pre class="brush: js notranslate">let a = 5; // 00000000000000000000000000000101 +<pre class="brush: js">let a = 5; // 00000000000000000000000000000101 a ^= 3; // 00000000000000000000000000000011 console.log(a); // 00000000000000000000000000000110 diff --git a/files/zh-cn/web/javascript/reference/operators/decrement/index.html b/files/zh-cn/web/javascript/reference/operators/decrement/index.html index aca67c15f9..8103a647d1 100644 --- a/files/zh-cn/web/javascript/reference/operators/decrement/index.html +++ b/files/zh-cn/web/javascript/reference/operators/decrement/index.html @@ -22,7 +22,7 @@ original_slug: Web/JavaScript/Reference/Operators/自减 <h2 id="语法"><br> 语法</h2> -<pre class="syntaxbox notranslate"><strong>操作符:</strong> <var>x</var>-- or --<var>x</var> +<pre class="syntaxbox"><strong>操作符:</strong> <var>x</var>-- or --<var>x</var> </pre> <h2 id="语法细节">语法细节</h2> @@ -35,7 +35,7 @@ original_slug: Web/JavaScript/Reference/Operators/自减 <h3 id="后缀式">后缀式</h3> -<pre class="brush: js notranslate">let x = 3; +<pre class="brush: js">let x = 3; y = x--; // y = 3 @@ -44,7 +44,7 @@ y = x--; <h3 id="前缀式">前缀式</h3> -<pre class="brush: js notranslate">let a = 2; +<pre class="brush: js">let a = 2; b = --a; // a = 1 diff --git a/files/zh-cn/web/javascript/reference/operators/delete/index.html b/files/zh-cn/web/javascript/reference/operators/delete/index.html index f460f0e268..ce9d2120a4 100644 --- a/files/zh-cn/web/javascript/reference/operators/delete/index.html +++ b/files/zh-cn/web/javascript/reference/operators/delete/index.html @@ -20,12 +20,12 @@ translation_of: Web/JavaScript/Reference/Operators/delete <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate">delete <em>expression</em> +<pre class="syntaxbox">delete <em>expression</em> </pre> <p> <em>expression</em> 的计算结果应该是某个属性的引用,例如:</p> -<pre class="syntaxbox notranslate">delete <em>object.property</em> +<pre class="syntaxbox">delete <em>object.property</em> delete <em>object</em>['<em>property</em>'] </pre> @@ -72,7 +72,7 @@ delete <em>object</em>['<em>property</em>'] <p>下面的代码块给出了一个简单的例子:</p> -<pre class="brush: js notranslate">var Employee = { +<pre class="brush: js">var Employee = { age: 28, name: 'abc', designation: 'developer' @@ -89,14 +89,14 @@ console.log(delete Employee.salary); // returns true</pre> <p>当一个属性被设置为不可设置,delete操作将不会有任何效果,并且会返回false。在严格模式下会抛出语法错误({{jsxref("SyntaxError")}})。</p> -<pre class="brush: js notranslate">var Employee = {}; +<pre class="brush: js">var Employee = {}; Object.defineProperty(Employee, 'name', {configurable: false}); console.log(delete Employee.name); // returns false</pre> <p>{{jsxref("Statements/var","var")}}, {{jsxref("Statements/let","let")}}以及{{jsxref("Statements/const","const")}}创建的不可设置的属性不能被delete操作删除。</p> -<pre class="brush: js notranslate">var nameOther = 'XYZ'; +<pre class="brush: js">var nameOther = 'XYZ'; // 通过以下方法获取全局属性: Object.getOwnPropertyDescriptor(window, 'nameOther'); @@ -116,7 +116,7 @@ delete nameOther; // return false</pre> <p>在严格模式下,如果对一个变量的直接引用、函数的参数或者函数名使用delete操作,将会抛出语法错误({{jsxref("SyntaxError")}})。因此,为避免严格模式下的语法错误,必须以<code>delete object.property</code>或<code>delete object['property']</code>的形式使用delete运算符。</p> -<pre class="brush: js notranslate">Object.defineProperty(globalThis, 'variable1', { value: 10, configurable: true, }); +<pre class="brush: js">Object.defineProperty(globalThis, 'variable1', { value: 10, configurable: true, }); Object.defineProperty(globalThis, 'variable2', { value: 10, configurable: false, }); console.log(delete variable1); // true @@ -125,7 +125,7 @@ console.log(delete variable1); // true console.log(delete variable2); // false </pre> -<pre class="brush: js notranslate">function func(param) { +<pre class="brush: js">function func(param) { // SyntaxError in strict mode. console.log(delete param); // false } @@ -140,7 +140,7 @@ console.log(delete func); // false <p>任何使用var声明的变量都会被标记为不可设置的。在下面的例子中,salary是不可设置的以及不能被删除的。在非严格模式下,下面的delete操作将会返回false。</p> -<pre class="brush: js notranslate">function Employee() { +<pre class="brush: js">function Employee() { delete salary; var salary; } @@ -149,7 +149,7 @@ Employee();</pre> <p>让我们来看看相同的代码在严格模式下会有怎样的表现。会抛出一个语法错误( <code>SyntaxError)而不是返回false。</code></p> -<pre class="brush: js notranslate">"use strict"; +<pre class="brush: js">"use strict"; function Employee() { delete salary; // SyntaxError @@ -167,7 +167,7 @@ delete DemoFunction; // SyntaxError</pre> <h2 id="示例">示例</h2> -<pre class="brush: js notranslate">// 在全局作用域创建 adminName 属性 +<pre class="brush: js">// 在全局作用域创建 adminName 属性 adminName = 'xyz'; // 在全局作用域创建 empCount 属性 @@ -213,7 +213,7 @@ function f() { <p>在下面的示例中,我们删除一个对象的自己的属性,而原型链上具有相同名称的属性可用:</p> -<pre class="brush: js notranslate">function Foo() { +<pre class="brush: js">function Foo() { this.bar = 10; } @@ -240,7 +240,7 @@ console.log(foo.bar); //undefined <p>当用 <code>delete</code> 操作符删除一个数组元素时,被删除的元素已经不再属于该数组。下面的例子中用 <code>delete </code>删除了<code> trees[3]</code>。</p> -<pre class="brush: js notranslate">var trees = ["redwood","bay","cedar","oak","maple"]; +<pre class="brush: js">var trees = ["redwood","bay","cedar","oak","maple"]; delete trees[3]; if (3 in trees) { // 这里不会执行 @@ -249,7 +249,7 @@ if (3 in trees) { <p>如果你想让一个数组元素继续存在但是其值是 <code>undefined</code>,那么可以使用将 <code>undefined</code> 赋值给这个元素而不是使用 <code>delete</code>。下面的例子中,trees[3] 被赋值为 <code>undefined</code>,但该元素仍然存在。</p> -<pre class="brush: js notranslate">var trees = ["redwood","bay","cedar","oak","maple"]; +<pre class="brush: js">var trees = ["redwood","bay","cedar","oak","maple"]; trees[3] = undefined; if (3 in trees) { // 这里会被执行 @@ -257,7 +257,7 @@ if (3 in trees) { <p>如果你想通过改变数组的内容来移除一个数组元素,请使用{{jsxref("Array.splice()", "splice()")}} 方法。在下面的例子中,通过使用{{jsxref("Array.splice()", "splice()")}},将trees[3]从数组中移除。</p> -<pre class="brush: js notranslate">var trees = ['redwood', 'bay', 'cedar', 'oak', 'maple']; +<pre class="brush: js">var trees = ['redwood', 'bay', 'cedar', 'oak', 'maple']; trees.splice(3,1); console.log(trees); // ["redwood", "bay", "cedar", "maple"] </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/division/index.html b/files/zh-cn/web/javascript/reference/operators/division/index.html index 8bfc53db1f..d1af1e83a0 100644 --- a/files/zh-cn/web/javascript/reference/operators/division/index.html +++ b/files/zh-cn/web/javascript/reference/operators/division/index.html @@ -20,14 +20,14 @@ translation_of: Web/JavaScript/Reference/Operators/Division <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>x</var> / <var>y</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>x</var> / <var>y</var> </pre> <h2 id="例子">例子</h2> <h3 id="基本除法">基本除法</h3> -<pre class="brush: js notranslate">1 / 2 // 0.5 +<pre class="brush: js">1 / 2 // 0.5 Math.floor(3 / 2) // 1 @@ -36,7 +36,7 @@ Math.floor(3 / 2) // 1 <h3 id="除以0">除以0</h3> -<pre class="brush: js notranslate">2.0 / 0 // Infinity +<pre class="brush: js">2.0 / 0 // Infinity 2.0 / 0.0 // Infinity, because 0.0 === 0 diff --git a/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html index a5afd52f49..a9d3508d00 100644 --- a/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Division_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x /= y +<pre class="syntaxbox"><strong>Operator:</strong> x /= y <strong>Meaning:</strong> x = x / y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_division_assignment">Using division assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variable +<pre class="brush: js">// Assuming the following variable // bar = 5 bar /= 2 // 2.5 diff --git a/files/zh-cn/web/javascript/reference/operators/equality/index.html b/files/zh-cn/web/javascript/reference/operators/equality/index.html index fadd413b17..5ea543e057 100644 --- a/files/zh-cn/web/javascript/reference/operators/equality/index.html +++ b/files/zh-cn/web/javascript/reference/operators/equality/index.html @@ -15,7 +15,7 @@ original_slug: Web/JavaScript/Reference/Operators/相等 <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">x == y +<pre class="syntaxbox">x == y </pre> <h2 id="描述">描述</h2> @@ -52,12 +52,12 @@ original_slug: Web/JavaScript/Reference/Operators/相等 <h3 id="没有类型转换的比较">没有类型转换的比较</h3> -<pre class="brush: js notranslate">1 == 1; // true +<pre class="brush: js">1 == 1; // true "hello" == "hello"; // true</pre> <h3 id="与类型转换比较">与类型转换比较</h3> -<pre class="brush: js notranslate">"1" == 1; // true +<pre class="brush: js">"1" == 1; // true 1 == "1"; // true 0 == false; // true 0 == null; // false @@ -71,7 +71,7 @@ number1 == number2; // false</pre> <h3 id="对象比较">对象比较</h3> -<pre class="brush: js notranslate">const object1 = {"key": "value"} +<pre class="brush: js">const object1 = {"key": "value"} const object2 = {"key": "value"}; object1 == object2 // false @@ -81,7 +81,7 @@ object2 == object2 // true</pre> <p>请注意,使用构造的字符串<code>new String()</code>是对象。如果将其中之一与字符串文字进行比较,则该<code>String</code>对象将被转换为字符串文字并对其内容进行比较。但是,如果两个操作数都是<code>String</code>对象,则将它们作为对象进行比较,并且必须引用相同的对象才能进行比较:</p> -<pre class="brush: js notranslate">const string1 = "hello"; +<pre class="brush: js">const string1 = "hello"; const string2 = String("hello"); const string3 = new String("hello"); const string4 = new String("hello"); @@ -94,7 +94,7 @@ console.log(string4 == string4); // true</pre> <h3 id="比较日期和字符串">比较日期和字符串</h3> -<pre class="brush: js notranslate">const d = new Date('December 17, 1995 03:24:00'); +<pre class="brush: js">const d = new Date('December 17, 1995 03:24:00'); const s = d.toString(); // for example: "Sun Dec 17 1995 03:24:00 GMT-0800 (Pacific Standard Time)" console.log(d == s); //true</pre> diff --git a/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html b/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html index 26fbf9ff64..7e138abfa2 100644 --- a/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html +++ b/files/zh-cn/web/javascript/reference/operators/exponentiation/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>var1</var> ** <var>var2</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>var1</var> ** <var>var2</var> </pre> <h2 id="简介">简介</h2> @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation <p>在JavaScript里,你不可能写出一个不明确的求幂表达式。这就是说,你不能立刻将一个一元运算符(<code>+/-/~/!/delete/void/typeof</code>)放在基数前,这样做只会导致一个语法错误。</p> -<pre class="brush: js notranslate">-2 ** 2; +<pre class="brush: js">-2 ** 2; // 4 in Bash, -4 in other languages. // This is invalid in JavaScript, as the operation is ambiguous. @@ -44,7 +44,7 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation <h3 id="基本求幂">基本求幂</h3> -<pre class="brush: js notranslate">2 ** 3 // 8 +<pre class="brush: js">2 ** 3 // 8 3 ** 2 // 9 3 ** 2.5 // 15.588457268119896 10 ** -1 // 0.1 @@ -53,7 +53,7 @@ NaN ** 2 // NaN <h3 id="结合">结合</h3> -<pre class="brush: js notranslate">2 ** 3 ** 2 // 512 +<pre class="brush: js">2 ** 3 ** 2 // 512 2 ** (3 ** 2) // 512 (2 ** 3) ** 2 // 64</pre> @@ -61,12 +61,12 @@ NaN ** 2 // NaN <p>取求幂表达式的值的相反数:</p> -<pre class="brush: js notranslate">-(2 ** 2) // -4 +<pre class="brush: js">-(2 ** 2) // -4 </pre> <p>将求幂表达式的底数转化为一个负数:</p> -<pre class="brush: js notranslate">(-2) ** 2 // 4 +<pre class="brush: js">(-2) ** 2 // 4 </pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html index f9f53ca532..bd8e58da23 100644 --- a/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/exponentiation_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Exponentiation_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x **= y +<pre class="syntaxbox"><strong>Operator:</strong> x **= y <strong>Meaning:</strong> x = x ** y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_exponentiation_assignment">Using exponentiation assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variable +<pre class="brush: js">// Assuming the following variable // bar = 5 bar **= 2 // 25 diff --git a/files/zh-cn/web/javascript/reference/operators/greater_than/index.html b/files/zh-cn/web/javascript/reference/operators/greater_than/index.html index afb4a2d134..0c8c8a8328 100644 --- a/files/zh-cn/web/javascript/reference/operators/greater_than/index.html +++ b/files/zh-cn/web/javascript/reference/operators/greater_than/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">x > y</pre> +<pre class="syntaxbox">x > y</pre> <h2 id="描述">描述</h2> @@ -23,13 +23,13 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than <h3 id="字符串的比较">字符串的比较</h3> -<pre class="brush: js notranslate">console.log("a" > "b"); // false +<pre class="brush: js">console.log("a" > "b"); // false console.log("a" > "a"); // false console.log("a" > "3"); // true</pre> <h3 id="字符串和数字的比较">字符串和数字的比较</h3> -<pre class="brush: js notranslate">console.log("5" > 3); // true +<pre class="brush: js">console.log("5" > 3); // true console.log("3" > 3); // false console.log("3" > 5); // false @@ -41,18 +41,18 @@ console.log("3" > 5n); // false</pre> <h3 id="数字间的比较">数字间的比较</h3> -<pre class="brush: js notranslate">console.log(5 > 3); // true +<pre class="brush: js">console.log(5 > 3); // true console.log(3 > 3); // false console.log(3 > 5); // false</pre> <h3 id="数字和_BigInt_数据的比较">数字和 BigInt 数据的比较</h3> -<pre class="brush: js notranslate">console.log(5n > 3); // true +<pre class="brush: js">console.log(5n > 3); // true console.log(3 > 5n); // false</pre> <h3 id="Boolean_null_undefined_NaN的比较">Boolean, null, undefined, NaN的比较</h3> -<pre class="brush: js notranslate">console.log(true > false); // true +<pre class="brush: js">console.log(true > false); // true console.log(false > true); // false console.log(true > 0); // true diff --git a/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html b/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html index 9fa5b48436..f54a1061fa 100644 --- a/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html +++ b/files/zh-cn/web/javascript/reference/operators/greater_than_or_equal/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than_or_equal <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate"> x >= y</pre> +<pre class="syntaxbox"> x >= y</pre> <h2 id="Description">Description</h2> @@ -23,14 +23,14 @@ translation_of: Web/JavaScript/Reference/Operators/Greater_than_or_equal <h3 id="String_to_string_comparison">String to string comparison</h3> -<pre class="brush: js notranslate">console.log("a" >= "b"); // false +<pre class="brush: js">console.log("a" >= "b"); // false console.log("a" >= "a"); // true console.log("a" >= "3"); // true </pre> <h3 id="String_to_number_comparison">String to number comparison</h3> -<pre class="brush: js notranslate">console.log("5" >= 3); // true +<pre class="brush: js">console.log("5" >= 3); // true console.log("3" >= 3); // true console.log("3" >= 5); // false @@ -39,19 +39,19 @@ console.log(5 >= "hello"); // false</pre> <h3 id="Number_to_Number_comparison">Number to Number comparison</h3> -<pre class="brush: js notranslate">console.log(5 >= 3); // true +<pre class="brush: js">console.log(5 >= 3); // true console.log(3 >= 3); // true console.log(3 >= 5); // false</pre> <h3 id="Number_to_BigInt_comparison">Number to BigInt comparison</h3> -<pre class="brush: js notranslate">console.log(5n >= 3); // true +<pre class="brush: js">console.log(5n >= 3); // true console.log(3 >= 3n); // true console.log(3 >= 5n); // false</pre> <h3 id="Comparing_Boolean_null_undefined_NaN">Comparing Boolean, null, undefined, NaN</h3> -<pre class="brush: js notranslate">console.log(true >= false); // true +<pre class="brush: js">console.log(true >= false); // true console.log(true >= true); // true console.log(false >= true); // false diff --git a/files/zh-cn/web/javascript/reference/operators/in/index.html b/files/zh-cn/web/javascript/reference/operators/in/index.html index 2ac7bb0ed4..f974698598 100644 --- a/files/zh-cn/web/javascript/reference/operators/in/index.html +++ b/files/zh-cn/web/javascript/reference/operators/in/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Operators/in <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="syntaxbox notranslate"><em>prop</em> in <em>object</em></pre> +<pre class="syntaxbox"><em>prop</em> in <em>object</em></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Operators/in <p>下面的例子演示了一些 <code>in</code> 运算符的用法。</p> -<pre class="brush:js notranslate">// 数组 +<pre class="brush:js">// 数组 var trees = new Array("redwood", "bay", "cedar", "oak", "maple"); 0 in trees // 返回true 3 in trees // 返回true @@ -58,7 +58,7 @@ var mycar = {make: "Honda", model: "Accord", year: 1998}; <p><code>in</code>右操作数必须是一个对象值。例如,你可以指定使用<code>String</code>构造函数创建的字符串,但不能指定字符串文字。</p> -<pre class="brush:js notranslate">var color1 = new String("green"); +<pre class="brush:js">var color1 = new String("green"); "length" in color1 // 返回true var color2 = "coral"; "length" in color2 // 报错(color2不是对象) @@ -68,7 +68,7 @@ var color2 = "coral"; <p>如果你使用 <code><a href="/zh-CN/docs/JavaScript/Reference/Operators/delete" title="zh-CN/docs/JavaScript/Reference/Operators/Special/delete">delete</a></code> 运算符删除了一个属性,则 <code>in</code> 运算符对所删除属性返回 <code>false</code>。</p> -<pre class="brush:js notranslate">var mycar = {make: "Honda", model: "Accord", year: 1998}; +<pre class="brush:js">var mycar = {make: "Honda", model: "Accord", year: 1998}; delete mycar.make; "make" in mycar; // 返回false @@ -79,12 +79,12 @@ delete trees[3]; <p>如果你只是将一个属性的值赋值为{{jsxref("Global_Objects/undefined", "undefined")}},而没有删除它,则 <code>in</code> 运算仍然会返回<code>true</code>。</p> -<pre class="brush:js notranslate">var mycar = {make: "Honda", model: "Accord", year: 1998}; +<pre class="brush:js">var mycar = {make: "Honda", model: "Accord", year: 1998}; mycar.make = undefined; "make" in mycar; // 返回true </pre> -<pre class="brush:js notranslate">var trees = new Array("redwood", "bay", "cedar", "oak", "maple"); +<pre class="brush:js">var trees = new Array("redwood", "bay", "cedar", "oak", "maple"); trees[3] = undefined; 3 in trees; // 返回true </pre> @@ -93,7 +93,7 @@ trees[3] = undefined; <p>如果一个属性是从原型链上继承来的,<code>in</code> 运算符也会返回 <code>true</code>。</p> -<pre class="brush:js notranslate">"toString" in {}; // 返回true +<pre class="brush:js">"toString" in {}; // 返回true </pre> <h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/increment/index.html b/files/zh-cn/web/javascript/reference/operators/increment/index.html index afe307f389..31620cb751 100644 --- a/files/zh-cn/web/javascript/reference/operators/increment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/increment/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Operators/Increment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>x</var>++ or ++<var>x</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>x</var>++ or ++<var>x</var> </pre> <h2 id="描述">描述</h2> @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Operators/Increment <h3 id="后置自增Postfix_increment">后置自增(Postfix increment)</h3> -<pre class="brush: js notranslate">let x = 3; +<pre class="brush: js">let x = 3; y = x++; // y = 3 @@ -39,7 +39,7 @@ y = x++; <h3 id="前置自增Prefix_increment">前置自增(Prefix increment)</h3> -<pre class="brush: js notranslate">let a = 2; +<pre class="brush: js">let a = 2; b = ++a; // a = 3 diff --git a/files/zh-cn/web/javascript/reference/operators/inequality/index.html b/files/zh-cn/web/javascript/reference/operators/inequality/index.html index 11b16d1c2e..cbc90433e7 100644 --- a/files/zh-cn/web/javascript/reference/operators/inequality/index.html +++ b/files/zh-cn/web/javascript/reference/operators/inequality/index.html @@ -18,13 +18,13 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">x != y</pre> +<pre class="syntaxbox">x != y</pre> <h2 id="描述">描述</h2> <p>不等式运算符检查其操作数是否不相等。这是<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Equality">等于</a>运算符的取反,因此以下两行将始终给出相同的结果: </p> -<pre class="brush: js notranslate">x != y +<pre class="brush: js">x != y !(x == y)</pre> @@ -32,17 +32,17 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality <p>与等于运算符一样,不等于运算符将尝试转换和比较不同类型的操作数:</p> -<pre class="brush: js notranslate">3 != "3"; // false</pre> +<pre class="brush: js">3 != "3"; // false</pre> <p>为避免这种情况,并要求将不同类型视为不同,请使用<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Strict_inequality">严格的不等于</a>运算符:</p> -<pre class="brush: js notranslate">3 !== "3"; // true</pre> +<pre class="brush: js">3 !== "3"; // true</pre> <h2 id="例子">例子</h2> <h3 id="没有类型转换的比较">没有类型转换的比较</h3> -<pre class="brush: js notranslate">1 != 2; // true +<pre class="brush: js">1 != 2; // true "hello" != "hola"; // true 1 != 1; // false @@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Operators/Inequality <h3 id="与类型转换比较">与类型转换比较</h3> -<pre class="brush: js notranslate">"1" != 1; // false +<pre class="brush: js">"1" != 1; // false 1 != "1"; // false 0 != false; // false 0 != null; // true @@ -66,7 +66,7 @@ number1 != number2; // true</pre> <h3 id="对象比较">对象比较</h3> -<pre class="brush: js notranslate">const object1 = {"key": "value"} +<pre class="brush: js">const object1 = {"key": "value"} const object2 = {"key": "value"}; object1 != object2 // true diff --git a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html index a1e3c5a538..9bc5622462 100644 --- a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="notranslate"><code><em>object</em> instanceof <em>constructor</em></code></pre> +<pre><code><em>object</em> instanceof <em>constructor</em></code></pre> <h3 id="Parameters" name="Parameters">参数</h3> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof <p><code>instanceof</code> 运算符用来检测 <code>constructor.prototype </code>是否存在于参数 <code>object</code> 的原型链上。</p> -<pre class="brush: js notranslate">// 定义构造函数 +<pre class="brush: js">// 定义构造函数 function C(){} function D(){} @@ -87,7 +87,7 @@ o3 instanceof C; // true 因为 C.prototype 现在在 o3 的原型链上 <p>但是,使用对象文字符号创建的对象在这里是一个例外:虽然原型未定义,但 <code>instanceof Object</code> 返回 <code>true</code>。</p> -<pre class="brush: js notranslate">var simpleStr = "This is a simple string"; +<pre class="brush: js">var simpleStr = "This is a simple string"; var myString = new String(); var newStr = new String("String created with constructor"); var myDate = new Date(); @@ -113,7 +113,7 @@ myDate instanceof String; // 返回 false</pre> <p>下面的代码创建了一个类型 <code>Car</code>,以及该类型的对象实例 <code>mycar</code>. <code>instanceof</code> 运算符表明了这个 <code>mycar</code> 对象既属于 <code>Car</code> 类型,又属于 <code>Object</code> 类型。</p> -<pre class="brush: js notranslate">function Car(make, model, year) { +<pre class="brush: js">function Car(make, model, year) { this.make = make; this.model = model; this.year = year; @@ -128,13 +128,13 @@ var b = mycar instanceof Object; // 返回 true <p>要检测对象不是某个构造函数的实例时,你可以这样做</p> -<pre class="brush: js notranslate">if (!(mycar instanceof Car)) { +<pre class="brush: js">if (!(mycar instanceof Car)) { // Do something, like mycar = new Car(mycar) }</pre> <p>这和以下代码完全不同</p> -<pre class="brush: js notranslate">if (!mycar instanceof Car)</pre> +<pre class="brush: js">if (!mycar instanceof Car)</pre> <p>这段代码永远会得到 <code>false</code>(<code>!mycar</code> 将在 <code>instanceof</code> 之前被处理,所以你总是在验证一个布尔值是否是 <code>Car</code> 的一个实例)。</p> diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift/index.html b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html index 83fe088941..4bae0bcde0 100644 --- a/files/zh-cn/web/javascript/reference/operators/left_shift/index.html +++ b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> << <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> << <var>b</var></code> </pre> <h2 id="描述">描述</h2> @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift <p>例如, <code>9 << 2</code> 得出 36:</p> -<pre class="brush: js notranslate">. 9 (十进制): 00000000000000000000000000001001 (二进制) +<pre class="brush: js">. 9 (十进制): 00000000000000000000000000001001 (二进制) -------------------------------- 9 << 2 (十进制): 00000000000000000000000000100100 (二进制) = 36 (十进制) </pre> @@ -34,7 +34,7 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift <h3 id="使用左移">使用左移</h3> -<pre class="brush: js notranslate">9 << 3; // 72 +<pre class="brush: js">9 << 3; // 72 // 9 * 2³ = 9 * 8 = 72 </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html index ccf5bbce00..e48b9616d0 100644 --- a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Left_shift_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x <<= y +<pre class="syntaxbox"><strong>Operator:</strong> x <<= y <strong>Meaning:</strong> x = x << y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_left_shift_assignment">Using left shift assignment</h3> -<pre class="brush: js notranslate">let a = 5; +<pre class="brush: js">let a = 5; // 00000000000000000000000000000101 a <<= 2; // 20 diff --git a/files/zh-cn/web/javascript/reference/operators/less_than/index.html b/files/zh-cn/web/javascript/reference/operators/less_than/index.html index 1a33554b98..d98a89f03c 100644 --- a/files/zh-cn/web/javascript/reference/operators/less_than/index.html +++ b/files/zh-cn/web/javascript/reference/operators/less_than/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"> x < y</pre> +<pre class="syntaxbox"> x < y</pre> <h2 id="Description">Description</h2> @@ -38,13 +38,13 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than <h3 id="String_to_string_comparison">String to string comparison</h3> -<pre class="brush: js notranslate">console.log("a" < "b"); // true +<pre class="brush: js">console.log("a" < "b"); // true console.log("a" < "a"); // false console.log("a" < "3"); // false</pre> <h3 id="String_to_number_comparison">String to number comparison</h3> -<pre class="brush: js notranslate">console.log("5" < 3); // false +<pre class="brush: js">console.log("5" < 3); // false console.log("3" < 3); // false console.log("3" < 5); // true @@ -56,18 +56,18 @@ console.log("3" < 5n); // true</pre> <h3 id="Number_to_Number_comparison">Number to Number comparison</h3> -<pre class="brush: js notranslate">console.log(5 < 3); // false +<pre class="brush: js">console.log(5 < 3); // false console.log(3 < 3); // false console.log(3 < 5); // true</pre> <h3 id="Number_to_BigInt_comparison">Number to BigInt comparison</h3> -<pre class="brush: js notranslate">console.log(5n < 3); // false +<pre class="brush: js">console.log(5n < 3); // false console.log(3 < 5n); // true</pre> <h3 id="Comparing_Boolean_null_undefined_NaN">Comparing Boolean, null, undefined, NaN</h3> -<pre class="brush: js notranslate">console.log(true < false); // false +<pre class="brush: js">console.log(true < false); // false console.log(false < true); // true console.log(0 < true); // true diff --git a/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html b/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html index 97a6f6746b..498dc2bbfd 100644 --- a/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html +++ b/files/zh-cn/web/javascript/reference/operators/less_than_or_equal/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than_or_equal <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate"> x <= y</pre> +<pre class="syntaxbox"> x <= y</pre> <h2 id="Description">Description</h2> @@ -23,14 +23,14 @@ translation_of: Web/JavaScript/Reference/Operators/Less_than_or_equal <h3 id="String_to_string_comparison">String to string comparison</h3> -<pre class="brush: js notranslate">console.log("a" <= "b"); // true +<pre class="brush: js">console.log("a" <= "b"); // true console.log("a" <= "a"); // true console.log("a" <= "3"); // false </pre> <h3 id="String_to_number_comparison">String to number comparison</h3> -<pre class="brush: js notranslate">console.log("5" <= 3); // false +<pre class="brush: js">console.log("5" <= 3); // false console.log("3" <= 3); // true console.log("3" <= 5); // true @@ -39,19 +39,19 @@ console.log(5 <= "hello"); // false</pre> <h3 id="Number_to_Number_comparison">Number to Number comparison</h3> -<pre class="brush: js notranslate">console.log(5 <= 3); // false +<pre class="brush: js">console.log(5 <= 3); // false console.log(3 <= 3); // true console.log(3 <= 5); // true</pre> <h3 id="Number_to_BigInt_comparison">Number to BigInt comparison</h3> -<pre class="brush: js notranslate">console.log(5n <= 3); // false +<pre class="brush: js">console.log(5n <= 3); // false console.log(3 <= 3n); // true console.log(3 <= 5n); // true</pre> <h3 id="Comparing_Boolean_null_undefined_NaN">Comparing Boolean, null, undefined, NaN</h3> -<pre class="brush: js notranslate">console.log(true <= false); // false +<pre class="brush: js">console.log(true <= false); // false console.log(true <= true); // true console.log(false <= true); // true diff --git a/files/zh-cn/web/javascript/reference/operators/logical_and/index.html b/files/zh-cn/web/javascript/reference/operators/logical_and/index.html index 78c4eee070..e418a76518 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_and/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_and/index.html @@ -14,7 +14,7 @@ original_slug: Web/JavaScript/Reference/Operators/逻辑和 <h2 id="Syntax">Syntax</h2> -<pre class="syntaxbox notranslate"><em>expr1</em> && <em>expr2</em> +<pre class="syntaxbox"><em>expr1</em> && <em>expr2</em> </pre> <h2 id="Description">Description</h2> @@ -43,7 +43,7 @@ original_slug: Web/JavaScript/Reference/Operators/逻辑和 <p>Short circuit means that the <code><em>expr</em></code> part above is <strong>not evaluated</strong>, hence any side effects of doing so do not take effect (e.g., if <code><em>expr</em></code> 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 notranslate">function A(){ console.log('called A'); return false; } +<pre class="brush: js">function A(){ console.log('called A'); return false; } function B(){ console.log('called B'); return true; } console.log( A() && B() ); @@ -55,7 +55,7 @@ console.log( A() && B() ); <p>The following expressions might seem equivalent, but they are not, because the <code>&&</code> operator is executed before the <code>||</code> operator (see <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">operator precedence</a>).</p> -<pre class="brush: js notranslate">true || false && false // returns true, because && is executed first +<pre class="brush: js">true || false && false // returns true, because && is executed first (true || false) && false // returns false, because operator precedence cannot apply</pre> <h2 id="Examples">Examples</h2> @@ -64,7 +64,7 @@ console.log( A() && B() ); <p>The following code shows examples of the <code>&&</code> (logical AND) operator.</p> -<pre class="brush: js notranslate">a1 = true && true // t && t returns true +<pre class="brush: js">a1 = true && true // t && t returns true a2 = true && false // t && f returns false a3 = false && true // f && t returns false a4 = false && (3 == 4) // f && f returns false @@ -80,21 +80,21 @@ a9 = false && '' // f && f returns false</pre> <p>The following operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 && bCondition2</pre> +<pre class="brush: js">bCondition1 && bCondition2</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">!(!bCondition1 || !bCondition2)</pre> +<pre class="brush: js">!(!bCondition1 || !bCondition2)</pre> <h4 id="Converting_OR_to_AND">Converting OR to AND</h4> <p>The following operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 || bCondition2</pre> +<pre class="brush: js">bCondition1 || bCondition2</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">!(!bCondition1 && !bCondition2)</pre> +<pre class="brush: js">!(!bCondition1 && !bCondition2)</pre> <h3 id="Removing_nested_parentheses">Removing nested parentheses</h3> @@ -102,11 +102,11 @@ a9 = false && '' // f && f returns false</pre> <p>The following composite operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 || (bCondition2 && bCondition3)</pre> +<pre class="brush: js">bCondition1 || (bCondition2 && bCondition3)</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">bCondition1 || bCondition2 && bCondition3</pre> +<pre class="brush: js">bCondition1 || bCondition2 && bCondition3</pre> <h2 id="Specifications">Specifications</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html index 3ed9a1582a..4ee00585a5 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_and_assignment/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_AND_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><em>expr1</em> &&= <em>expr2</em> +<pre class="syntaxbox"><em>expr1</em> &&= <em>expr2</em> </pre> <h2 id="描述">描述</h2> @@ -28,18 +28,18 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_AND_assignment <p>Logical AND assignment short-circuits as well meaning that <code>x &&= y</code> is equivalent to:</p> -<pre class="brush: js notranslate">x && (x = y);</pre> +<pre class="brush: js">x && (x = y);</pre> <p>And not equivalent to the following which would always perform an assignment:</p> -<pre class="brush: js notranslate example-bad">x = x && y; +<pre class="brush: js example-bad">x = x && y; </pre> <h2 id="例子">例子</h2> <h3 id="Using_logical_AND_assignment">Using logical AND assignment</h3> -<pre class="brush: js notranslate">let x = 0; +<pre class="brush: js">let x = 0; let y = 1; x &&= 0; // 0 diff --git a/files/zh-cn/web/javascript/reference/operators/logical_not/index.html b/files/zh-cn/web/javascript/reference/operators/logical_not/index.html index f05bfb180a..e27ad4db4f 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_not/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_not/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_NOT <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">!<var>expr</var> +<pre class="syntaxbox">!<var>expr</var> </pre> <h2 id="Description">Description</h2> @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_NOT <p>The following code shows examples of the <code>!</code> (logical NOT) operator.</p> -<pre class="brush: js notranslate">n1 = !true // !t returns false +<pre class="brush: js">n1 = !true // !t returns false n2 = !false // !f returns true n3 = !'' // !f returns true n4 = !'Cat' // !t returns false</pre> @@ -51,7 +51,7 @@ n4 = !'Cat' // !t returns false</pre> <p>The same conversion can be done through the {{jsxref("Global_Objects/Boolean/Boolean", "Boolean")}} function.</p> -<pre class="brush: js notranslate">n1 = !!true // !!truthy returns true +<pre class="brush: js">n1 = !!true // !!truthy returns true n2 = !!{} // !!truthy returns true: <strong>any</strong> object is truthy... n3 = !!(new Boolean(false)) // ...even Boolean objects with a false <em>.valueOf()</em>! n4 = !!false // !!falsy returns false @@ -62,11 +62,11 @@ n6 = !!Boolean(false) // !!falsy returns false</pre> <p>The following operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">!!bCondition</pre> +<pre class="brush: js">!!bCondition</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">bCondition</pre> +<pre class="brush: js">bCondition</pre> <h2 id="Specifications">Specifications</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html index a57c18e5c2..c4fea43591 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_nullish_assignment/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_nullish_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><em>expr1</em> ??= <em>expr2</em> +<pre class="syntaxbox"><em>expr1</em> ??= <em>expr2</em> </pre> <h2 id="描述">描述</h2> @@ -28,18 +28,18 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_nullish_assignment <p>逻辑空赋值的语法短路也意味着 <code>x ??= y</code> 等价于:</p> -<pre class="brush: js notranslate">x ?? (x = y);</pre> +<pre class="brush: js">x ?? (x = y);</pre> <p>而不等价于如下的表达式,因为其一定会发生赋值:</p> -<pre class="brush: js notranslate example-bad">x = x ?? y; +<pre class="brush: js example-bad">x = x ?? y; </pre> <h2 id="例子">例子</h2> <h3 id="使用逻辑空赋值">使用逻辑空赋值</h3> -<pre class="brush: js notranslate">function config(options) { +<pre class="brush: js">function config(options) { options.duration ??= 100; options.speed ??= 25; return options; diff --git a/files/zh-cn/web/javascript/reference/operators/logical_or/index.html b/files/zh-cn/web/javascript/reference/operators/logical_or/index.html index 1a8f881377..3604b99140 100644 --- a/files/zh-cn/web/javascript/reference/operators/logical_or/index.html +++ b/files/zh-cn/web/javascript/reference/operators/logical_or/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_OR <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><em>expr1</em> || <em>expr2</em> +<pre class="syntaxbox"><em>expr1</em> || <em>expr2</em> </pre> <h2 id="Description">Description</h2> @@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Operators/Logical_OR <p>Short circuit means that the <code><em>expr</em></code> part above is <strong>not evaluated</strong>, hence any side effects of doing so do not take effect (e.g., if <code><em>expr</em></code> 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 notranslate">function A(){ console.log('called A'); return false; } +<pre class="brush: js">function A(){ console.log('called A'); return false; } function B(){ console.log('called B'); return true; } console.log( B() || A() ); @@ -54,7 +54,7 @@ console.log( B() || A() ); <p>The following expressions might seem equivalent, but they are not, because the <code>&&</code> operator is executed before the <code>||</code> operator (see <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">operator precedence</a>).</p> -<pre class="brush: js notranslate">true || false && false // returns true, because && is executed first +<pre class="brush: js">true || false && false // returns true, because && is executed first (true || false) && false // returns false, because operator precedence cannot apply</pre> <h2 id="Examples">Examples</h2> @@ -63,7 +63,7 @@ console.log( B() || A() ); <p>The following code shows examples of the <code>||</code> (logical OR) operator.</p> -<pre class="brush: js notranslate">o1 = true || true // t || t returns true +<pre class="brush: js">o1 = true || true // t || t returns true o2 = false || true // f || t returns true o3 = true || false // t || f returns true o4 = false || (3 == 4) // f || f returns false @@ -85,21 +85,21 @@ o10 = false || varObject // f || object returns varObject <p>The following operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 && bCondition2</pre> +<pre class="brush: js">bCondition1 && bCondition2</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">!(!bCondition1 || !bCondition2)</pre> +<pre class="brush: js">!(!bCondition1 || !bCondition2)</pre> <h4 id="Converting_OR_to_AND">Converting OR to AND</h4> <p>The following operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 || bCondition2</pre> +<pre class="brush: js">bCondition1 || bCondition2</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">!(!bCondition1 && !bCondition2)</pre> +<pre class="brush: js">!(!bCondition1 && !bCondition2)</pre> <h3 id="Removing_nested_parentheses">Removing nested parentheses</h3> @@ -107,11 +107,11 @@ o10 = false || varObject // f || object returns varObject <p>The following composite operation involving <strong>booleans</strong>:</p> -<pre class="brush: js notranslate">bCondition1 && (bCondition2 || bCondition3)</pre> +<pre class="brush: js">bCondition1 && (bCondition2 || bCondition3)</pre> <p>is always equal to:</p> -<pre class="brush: js notranslate">!(!bCondition1 || !bCondition2 && !bCondition3)</pre> +<pre class="brush: js">!(!bCondition1 || !bCondition2 && !bCondition3)</pre> <h2 id="Specifications">Specifications</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/multiplication/index.html b/files/zh-cn/web/javascript/reference/operators/multiplication/index.html index db346f4cbe..a37d1e7a54 100644 --- a/files/zh-cn/web/javascript/reference/operators/multiplication/index.html +++ b/files/zh-cn/web/javascript/reference/operators/multiplication/index.html @@ -15,25 +15,25 @@ translation_of: Web/JavaScript/Reference/Operators/Multiplication <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>x</var> * <var>y</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>x</var> * <var>y</var> </pre> <h2 id="例子">例子</h2> <h3 id="使用数字相乘">使用数字相乘</h3> -<pre class="brush: js notranslate"> 2 * 2 // 4 +<pre class="brush: js"> 2 * 2 // 4 -2 * 2 // -4 </pre> <h3 id="使用_Infinity_相乘">使用 Infinity 相乘</h3> -<pre class="brush: js notranslate">Infinity * 0 // NaN +<pre class="brush: js">Infinity * 0 // NaN Infinity * Infinity // Infinity</pre> <h3 id="使用非数字相乘">使用非数字相乘</h3> -<pre class="brush: js notranslate">'foo' * 2 // NaN</pre> +<pre class="brush: js">'foo' * 2 // NaN</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html index e05019acba..274729034b 100644 --- a/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/multiplication_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Multiplication_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x *= y +<pre class="syntaxbox"><strong>Operator:</strong> x *= y <strong>Meaning:</strong> x = x * y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_multiplication_assignment">Using multiplication assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variable +<pre class="brush: js">// Assuming the following variable // bar = 5 bar *= 2 // 10 diff --git a/files/zh-cn/web/javascript/reference/operators/new/index.html b/files/zh-cn/web/javascript/reference/operators/new/index.html index 0b2d5c24c7..e6833d4cc7 100644 --- a/files/zh-cn/web/javascript/reference/operators/new/index.html +++ b/files/zh-cn/web/javascript/reference/operators/new/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/new <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">new <em>constructor</em>[([<em>arguments</em>])]</pre> +<pre class="syntaxbox">new <em>constructor</em>[([<em>arguments</em>])]</pre> <h3 id="参数">参数</h3> @@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Operators/new <p>你可以使用 <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype">Function.prototype</a></code> 属性将共享属性添加到以前定义的对象类型。这定义了一个由该函数创建的所有对象共享的属性,而不仅仅是对象类型的其中一个实例。下面的代码将一个值为 <code>null</code> 的 <code>color</code> 属性添加到 <code>car</code> 类型的所有对象,然后仅在实例对象 <code>car1</code> 中用字符串 "<code>black</code>" 覆盖该值。详见 <a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype">prototype</a>。</p> -<pre class="brush: js notranslate">function Car() {} +<pre class="brush: js">function Car() {} car1 = new Car(); car2 = new Car(); @@ -95,7 +95,7 @@ console.log(car2.color) // original color <p>假设你要创建一个汽车的对象类型。你希望这个类型叫做car,这个类型具备make, model, year等属性,要做到这些,你需要写这样一个函数:</p> -<pre class="brush: js notranslate">function Car(make, model, year) { +<pre class="brush: js">function Car(make, model, year) { this.make = make; this.model = model; this.year = year; @@ -104,19 +104,19 @@ console.log(car2.color) // original color <p>现在,你可以如下所示创建一个 <code>mycar</code> 的对象:</p> -<pre class="brush: js notranslate">var mycar = new Car("Eagle", "Talon TSi", 1993);</pre> +<pre class="brush: js">var mycar = new Car("Eagle", "Talon TSi", 1993);</pre> <p>这段代码创建了 <code>mycar</code> 并给他的属性指定值,于是 <code>mycar.make</code> 的值为"<code>Eagle</code>", <code>mycar.year</code> 的值为1993,以此类推。</p> <p>你可以通过调用 <code>new</code> 来创建任意个汽车对象。例如:</p> -<pre class="brush: js notranslate">var kenscar = new Car("Nissan", "300ZX", 1992);</pre> +<pre class="brush: js">var kenscar = new Car("Nissan", "300ZX", 1992);</pre> <h3 id="对象属性为其他对象">对象属性为其他对象</h3> <p>假设你定义了一个对象叫做 <code>person</code>:</p> -<pre class="brush: js notranslate">function Person(name, age, sex) { +<pre class="brush: js">function Person(name, age, sex) { this.name = name; this.age = age; this.sex = sex; @@ -125,13 +125,13 @@ console.log(car2.color) // original color <p>然后实例化两个新的 <code>person</code> 对象如下:</p> -<pre class="brush: js notranslate">var rand = new Person("Rand McNally", 33, "M"); +<pre class="brush: js">var rand = new Person("Rand McNally", 33, "M"); var ken = new Person("Ken Jones", 39, "M"); </pre> <p>然后你可以重写 <code>car</code> 的定义,添加一个值为 <code>person</code> 对象的 <code>owner</code> 属性,如下:</p> -<pre class="brush: js notranslate">function Car(make, model, year, owner) { +<pre class="brush: js">function Car(make, model, year, owner) { this.make = make; this.model = model; this.year = year; @@ -141,13 +141,13 @@ var ken = new Person("Ken Jones", 39, "M"); <p>为了实例化新的对象,你可以用如下代码:</p> -<pre class="brush: js notranslate">var car1 = new Car("Eagle", "Talon TSi", 1993, rand); +<pre class="brush: js">var car1 = new Car("Eagle", "Talon TSi", 1993, rand); var car2 = new Car("Nissan", "300ZX", 1992, ken); </pre> <p>创建对象时,并没有传字符串或数字给owner,而是传了对象 <code>rand</code> 和 <code>ken</code> 。这个时候,你可以这样来获取 <code>car2</code> 的owner的name:</p> -<pre class="brush: js notranslate">car2.owner.name</pre> +<pre class="brush: js">car2.owner.name</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html b/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html index 59b7443e60..1dfd0302a9 100644 --- a/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html +++ b/files/zh-cn/web/javascript/reference/operators/nullish_coalescing_operator/index.html @@ -23,7 +23,7 @@ translation_of: Web/JavaScript/Reference/Operators/Nullish_coalescing_operator <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>leftExpr</var> ?? <var>rightExpr</var> +<pre class="syntaxbox"><var>leftExpr</var> ?? <var>rightExpr</var> </pre> <h2 id="示例">示例</h2> @@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Operators/Nullish_coalescing_operator <p>在这个例子中,我们使用空值合并操作符为常量提供默认值,保证常量不为 <code>null</code> 或者 <code>undefined</code>。</p> -<pre class="brush: js notranslate">const nullValue = null; +<pre class="brush: js">const nullValue = null; const emptyText = ""; // 空字符串,是一个假值,Boolean("") === false const someNumber = 42; @@ -48,14 +48,14 @@ console.log(valC); // 42</pre> <p>以前,如果想为一个变量赋默认值,通常的做法是使用逻辑或操作符(<code><a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Logical_OR">||</a></code>):</p> -<pre class="brush: js notranslate">let foo; +<pre class="brush: js">let foo; // foo is never assigned any value so it is still undefined let someDummyText = foo || 'Hello!';</pre> <p>然而,由于 <code>||</code> 是一个布尔逻辑运算符,左侧的操作数会被强制转换成布尔值用于求值。任何假值(<code>0</code>, <code>''</code>, <code>NaN</code>, <code>null</code>, <code>undefined</code>)都不会被返回。这导致如果你使用<code>0</code>,<code>''</code>或<code>NaN</code>作为有效值,就会出现不可预料的后果。</p> -<pre class="brush: js notranslate">let count = 0; +<pre class="brush: js">let count = 0; let text = ""; let qty = count || 42; @@ -65,7 +65,7 @@ console.log(message); // "hi!",而不是 ""</pre> <p>空值合并操作符可以避免这种陷阱,其只在第一个操作数为<code>null</code> 或 <code>undefined</code> 时(而不是其它假值)返回第二个操作数:</p> -<pre class="brush: js notranslate">let myText = ''; // An empty string (which is also a falsy value) +<pre class="brush: js">let myText = ''; // An empty string (which is also a falsy value) let notFalsyText = myText || 'Hello world'; console.log(notFalsyText); // Hello world @@ -78,7 +78,7 @@ console.log(preservingFalsy); // '' (as myText is neither undefined nor null) <p>与 OR 和 AND 逻辑操作符相似,当左表达式不为 <code>null</code> 或 <code>undefined</code> 时,不会对右表达式进行求值。</p> -<pre class="brush: js notranslate">function A() { console.log('函数 A 被调用了'); return undefined; } +<pre class="brush: js">function A() { console.log('函数 A 被调用了'); return undefined; } function B() { console.log('函数 B 被调用了'); return false; } function C() { console.log('函数 C 被调用了'); return "foo"; } @@ -96,19 +96,19 @@ console.log( B() ?? C() ); <p>将 <code>??</code> 直接与 AND(<code>&&</code>)和 OR(<code>||</code>)操作符组合使用是不可取的。(译者注:应当是因为空值合并操作符和其他逻辑操作符之间的运算优先级/运算顺序是未定义的)这种情况下会抛出 <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></code> 。</p> -<pre class="brush: js example-bad notranslate">null || undefined ?? "foo"; // 抛出 SyntaxError +<pre class="brush: js example-bad">null || undefined ?? "foo"; // 抛出 SyntaxError true || undefined ?? "foo"; // 抛出 SyntaxError</pre> <p>但是,如果使用括号来显式表明运算优先级,是没有问题的:</p> -<pre class="brush: js example-good notranslate">(null || undefined ) ?? "foo"; // 返回 "foo" +<pre class="brush: js example-good">(null || undefined ) ?? "foo"; // 返回 "foo" </pre> <h3 id="与可选链式操作符(.)的关系">与可选链式操作符(<code>?.</code>)的关系</h3> <p>空值合并操作符针对 <code>undefined</code> 与 <code>null</code> 这两个值,<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Optional_chaining">可选链式操作符(<code>?.</code>)</a> 也是如此。在这访问属性可能为 <code>undefined</code> 与 <code>null</code> 的对象时,可选链式操作符非常有用。</p> -<pre class="brush: js notranslate">let foo = { someFooProp: "hi" }; +<pre class="brush: js">let foo = { someFooProp: "hi" }; console.log(foo.someFooProp?.toUpperCase()); // "HI" console.log(foo.someBarProp?.toUpperCase()); // undefined diff --git a/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html b/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html index 6f639f537a..e765e6d66b 100644 --- a/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html +++ b/files/zh-cn/web/javascript/reference/operators/optional_chaining/index.html @@ -26,7 +26,7 @@ original_slug: Web/JavaScript/Reference/Operators/可选链 <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><var>obj</var>?.<var>prop</var> +<pre class="syntaxbox"><var>obj</var>?.<var>prop</var> <var>obj</var>?.[<var>expr</var>] <var>arr</var>?.[<var>index</var>] <var>func</var>?.(<var>args</var>) @@ -38,19 +38,19 @@ original_slug: Web/JavaScript/Reference/Operators/可选链 <p>比如,思考一个存在嵌套结构的对象 <code>obj</code>。不使用可选链的话,查找一个深度嵌套的子属性时,需要验证之间的引用,例如:</p> -<pre class="brush: js notranslate">let nestedProp = obj.first && obj.first.second;</pre> +<pre class="brush: js">let nestedProp = obj.first && obj.first.second;</pre> <p>为了避免报错,在访问<code>obj.first.second</code>之前,要保证 <code>obj.first</code> 的值既不是 <code>null</code>,也不是 <code>undefined</code>。如果只是直接访问 <code>obj.first.second</code>,而不对 <code>obj.first</code> 进行校验,则有可能抛出错误。</p> <p>有了可选链操作符(<code>?.</code>),在访问 <code>obj.first.second</code> 之前,不再需要明确地校验 <code>obj.first</code> 的状态,再并用短路计算获取最终结果:</p> -<pre class="brush: js notranslate">let nestedProp = obj.first?.second;</pre> +<pre class="brush: js">let nestedProp = obj.first?.second;</pre> <p>通过使用 <code>?.</code> 操作符取代 <code>.</code> 操作符,JavaScript 会在尝试访问 <code>obj.first.second</code> 之前,先隐式地检查并确定 <code>obj.first</code> 既不是 <code>null</code> 也不是 <code>undefined</code>。如果<code>obj.first </code>是 <code>null</code> 或者 <code>undefined</code>,表达式将会短路计算直接返回 <code>undefined</code>。</p> <p>这等价于以下表达式,但实际上没有创建临时变量:</p> -<pre class="brush: js notranslate">let temp = obj.first; +<pre class="brush: js">let temp = obj.first; let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.second);</pre> <h3 id="可选链与函数调用">可选链与函数调用</h3> @@ -59,7 +59,7 @@ let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.secon <p>函数调用时如果被调用的方法不存在,使用可选链可以使表达式自动返回<code>undefined</code>而不是抛出一个异常。</p> -<pre class="brush: js notranslate">let result = someInterface.customMethod?.();</pre> +<pre class="brush: js">let result = someInterface.customMethod?.();</pre> <div class="blockIndicator note"> <p><strong>注意:</strong> 如果存在一个属性名且不是函数, 使用 <code>?.</code> 仍然会产生一个 {{JSxRef("TypeError")}} 异常 (<code>x.y</code><code> is not a function</code>).</p> @@ -73,7 +73,7 @@ let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.secon <p>如果使用<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">解构赋值</a>来解构的一个对象的回调函数或 fetch 方法,你可能得到不能当做函数直接调用的不存在的值,除非你已经校验了他们的存在性。使用<code>?.</code>的你可以忽略这些额外的校验:</p> -<pre class="brush: js notranslate">// ES2019的写法 +<pre class="brush: js">// ES2019的写法 function doSomething(onContent, onError) { try { // ... do something with the data @@ -86,7 +86,7 @@ function doSomething(onContent, onError) { } </pre> -<pre class="brush: js notranslate">// 使用可选链进行函数调用 +<pre class="brush: js">// 使用可选链进行函数调用 function doSomething(onContent, onError) { try { // ... do something with the data @@ -101,16 +101,16 @@ function doSomething(onContent, onError) { <p>当使用<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Property_Accessors#方括号表示法">方括号与属性名</a>的形式来访问属性时,你也可以使用可选链操作符:</p> -<pre class="brush: js notranslate">let nestedProp = obj?.['prop' + 'Name'];</pre> +<pre class="brush: js">let nestedProp = obj?.['prop' + 'Name'];</pre> <h3 id="可选链不能用于赋值">可选链不能用于赋值</h3> -<pre class="notranslate"><code>let object = {}; +<pre><code>let object = {}; object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignment</code></pre> <h3 id="可选链访问数组元素">可选链访问数组元素</h3> -<pre class="notranslate">let arrayItem = arr?.[42];</pre> +<pre>let arrayItem = arr?.[42];</pre> <h2 id="例子">例子</h2> @@ -118,7 +118,7 @@ object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignm <p>如下的例子在一个不含 <code>bar</code> 成员的 Map 中查找 <code>bar</code> 成员的 <code>name</code> 属性,因此结果是 <code>undefined</code>。</p> -<pre class="brush: js notranslate">let myMap = new Map(); +<pre class="brush: js">let myMap = new Map(); myMap.set("foo", {name: "baz", desc: "inga"}); let nameBar = myMap.get("bar")?.name;</pre> @@ -127,7 +127,7 @@ let nameBar = myMap.get("bar")?.name;</pre> <p>当在表达式中使用可选链时,如果左操作数是 <code>null</code> 或 <code>undefined</code>,表达式将不会被计算,例如:</p> -<pre class="brush: js notranslate">let potentiallyNullObj = null; +<pre class="brush: js">let potentiallyNullObj = null; let x = 0; let prop = potentiallyNullObj?.[x++]; @@ -138,7 +138,7 @@ console.log(x); // x 将不会被递增,依旧输出 0 <p>可以连续使用可选链读取多层嵌套结构:</p> -<pre class="brush: js notranslate">let customer = { +<pre class="brush: js">let customer = { name: "Carl", details: { age: 82, @@ -155,7 +155,7 @@ let duration = vacations.trip?.getTime?.(); <p>{{JSxRef("Operators/Nullish_Coalescing_Operator", "空值合并操作符")}}可以在使用可选链时设置一个默认值:</p> -<pre class="brush: js notranslate"><code>let customer = { +<pre class="brush: js"><code>let customer = { name: "Carl", details: { age: 82 } }; diff --git a/files/zh-cn/web/javascript/reference/operators/remainder/index.html b/files/zh-cn/web/javascript/reference/operators/remainder/index.html index f09292e4ff..a2d1e19fa6 100644 --- a/files/zh-cn/web/javascript/reference/operators/remainder/index.html +++ b/files/zh-cn/web/javascript/reference/operators/remainder/index.html @@ -21,14 +21,14 @@ original_slug: Web/JavaScript/Reference/Operators/取余 <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>var1</var> % <var>var2</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>var1</var> % <var>var2</var> </pre> <h2 id="示例">示例</h2> <h3 id="被除数为正数">被除数为正数</h3> -<pre class="brush: js notranslate"> 12 % 5 // 2 +<pre class="brush: js"> 12 % 5 // 2 1 % -2 // 1 1 % 2 // 1 2 % 3 // 2 @@ -37,13 +37,13 @@ original_slug: Web/JavaScript/Reference/Operators/取余 <h3 id="被除数为负数">被除数为负数</h3> -<pre class="brush: js notranslate">-12 % 5 // -2 +<pre class="brush: js">-12 % 5 // -2 -1 % 2 // -1 -4 % 2 // -0</pre> <h3 id="被除数为NaN">被除数为NaN</h3> -<pre class="brush: js notranslate">NaN % 2 // NaN</pre> +<pre class="brush: js">NaN % 2 // NaN</pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html index a9d015e467..d36fa7cdc3 100644 --- a/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/remainder_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Remainder_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x %= y +<pre class="syntaxbox"><strong>Operator:</strong> x %= y <strong>Meaning:</strong> x = x % y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_remainder_assignment">Using remainder assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variable +<pre class="brush: js">// Assuming the following variable // bar = 5 bar %= 2 // 1 diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift/index.html b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html index f049a499a9..583da5cafe 100644 --- a/files/zh-cn/web/javascript/reference/operators/right_shift/index.html +++ b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> >> <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> >> <var>b</var></code> </pre> <h2 id="Description">Description</h2> @@ -22,14 +22,14 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift <p>For example, <code>9 >> 2</code> yields 2:</p> -<pre class="brush: js notranslate">. 9 (base 10): 00000000000000000000000000001001 (base 2) +<pre class="brush: js">. 9 (base 10): 00000000000000000000000000001001 (base 2) -------------------------------- 9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10) </pre> <p>Likewise, <code>-9 >> 2</code> yields <code>-3</code>, because the sign is preserved:</p> -<pre class="brush: js notranslate">. -9 (base 10): 11111111111111111111111111110111 (base 2) +<pre class="brush: js">. -9 (base 10): 11111111111111111111111111110111 (base 2) -------------------------------- -9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10) </pre> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift <h3 id="Using_right_shift">Using right shift</h3> -<pre class="brush: js notranslate"> 9 >> 2; // 2 +<pre class="brush: js"> 9 >> 2; // 2 -9 >> 2; // -3 </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html index f9e8b3c8c4..0ebfbbd51e 100644 --- a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Right_shift_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x >>= y +<pre class="syntaxbox"><strong>Operator:</strong> x >>= y <strong>Meaning:</strong> x = x >> y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_right_shift_assignment">Using right shift assignment</h3> -<pre class="brush: js notranslate">let a = 5; // (00000000000000000000000000000101) +<pre class="brush: js">let a = 5; // (00000000000000000000000000000101) a >>= 2; // 1 (00000000000000000000000000000001) let b = -5; // (-00000000000000000000000000000101) diff --git a/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html b/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html index 0397ee8e96..3f21c5b960 100644 --- a/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html +++ b/files/zh-cn/web/javascript/reference/operators/spread_syntax/index.html @@ -20,15 +20,15 @@ translation_of: Web/JavaScript/Reference/Operators/Spread_syntax <p>函数调用:</p> -<pre class="syntaxbox notranslate">myFunction(...iterableObj);</pre> +<pre class="syntaxbox">myFunction(...iterableObj);</pre> <p>字面量数组构造或字符串:</p> -<pre class="notranslate">[...iterableObj, '4', ...'hello', 6];</pre> +<pre>[...iterableObj, '4', ...'hello', 6];</pre> <p>构造字面量对象时,进行克隆或者属性拷贝(ECMAScript 2018规范新增特性):</p> -<pre class="syntaxbox notranslate">let objClone = { ...obj };</pre> +<pre class="syntaxbox">let objClone = { ...obj };</pre> <h2 id="示例">示例</h2> @@ -38,19 +38,19 @@ translation_of: Web/JavaScript/Reference/Operators/Spread_syntax <p>如果想将数组元素迭代为函数参数,一般使用{{jsxref( "Function.prototype.apply")}} 的方式进行调用。</p> -<pre class="brush: js notranslate">function myFunction(x, y, z) { } +<pre class="brush: js">function myFunction(x, y, z) { } var args = [0, 1, 2]; myFunction.apply(null, args);</pre> <p>有了展开语法,可以这样写:</p> -<pre class="brush: js notranslate"><code>function myFunction(x, y, z) { } +<pre class="brush: js"><code>function myFunction(x, y, z) { } var args = [0, 1, 2]; myFunction(...args);</code></pre> <p>所有参数都可以通过展开语法来传值,也不限制多次使用展开语法。</p> -<pre class="brush: js notranslate">function myFunction(v, w, x, y, z) { } +<pre class="brush: js">function myFunction(v, w, x, y, z) { } var args = [0, 1]; myFunction(-1, ...args, 2, ...[3]);</pre> @@ -58,13 +58,13 @@ myFunction(-1, ...args, 2, ...[3]);</pre> <p>使用 <code>new</code> 关键字来调用构造函数时,不能<strong>直接</strong>使用数组+ <code>apply</code> 的方式(<code>apply</code> 执行的是调用 <code>[[Call]]</code> , 而不是构造 <code>[[Construct]]</code>)。当然, 有了展开语法, 将数组展开为构造函数的参数就很简单了:</p> -<pre class="brush: js notranslate">var dateFields = [1970, 0, 1]; // 1970年1月1日 +<pre class="brush: js">var dateFields = [1970, 0, 1]; // 1970年1月1日 var d = new Date(...dateFields);</font></font> </pre> <p>如果不使用展开语法, 想将数组元素传给构造函数, 实现方式可能是这样的:</p> -<pre class="brush: js notranslate">function applyAndNew(constructor, args) { +<pre class="brush: js">function applyAndNew(constructor, args) { function partial () { return constructor.apply(this, args); }; @@ -96,7 +96,7 @@ console.log(new myConstructorWithArguments); <p>没有展开语法的时候,只能组合使用 <code>push</code>, <code>splice</code>, <code>concat</code> 等方法,来将已有数组元素变成新数组的一部分。有了展开语法, 通过字面量方式, 构造新数组会变得更简单、更优雅:</p> -<pre class="brush: js notranslate">var parts = ['shoulders', 'knees']; +<pre class="brush: js">var parts = ['shoulders', 'knees']; var lyrics = ['head', ...parts, 'and', 'toes']; </font></font> // ["head", "shoulders", "knees", "and", "toes"] </pre> @@ -105,7 +105,7 @@ var lyrics = ['head', ...parts, 'and', 'toes']; </font></font> <h4 id="数组拷贝copy">数组拷贝(copy)</h4> -<pre class="brush: js notranslate">var arr = [1, 2, 3]; +<pre class="brush: js">var arr = [1, 2, 3]; var arr2 = [...arr]; // like arr.slice() arr2.push(4); @@ -115,7 +115,7 @@ arr2.push(4); <p><strong>提示:</strong> 实际上, 展开语法和 {{jsxref("Object.assign()")}} 行为一致, 执行的都是浅拷贝(只遍历一层)。如果想对多维数组进行深拷贝, 下面的示例就有些问题了。</p> -<pre class="brush: js notranslate">var a = [[1], [2], [3]]; +<pre class="brush: js">var a = [[1], [2], [3]]; var b = [...a]; b.shift().shift(); // 1 // Now array a is affected as well: [[2], [3]] @@ -125,28 +125,28 @@ b.shift().shift(); // 1 <p>{{jsxref("Array.concat")}} 函数常用于将一个数组连接到另一个数组的后面。如果不使用展开语法, 代码可能是下面这样的:</p> -<pre class="brush: js notranslate">var arr1 = [0, 1, 2]; +<pre class="brush: js">var arr1 = [0, 1, 2]; var arr2 = [3, 4, 5]; // 将 arr2 中所有元素附加到 arr1 后面并返回 var arr3 = arr1.concat(arr2);</pre> <p>使用展开语法:</p> -<pre class="brush: js notranslate">var arr1 = [0, 1, 2]; +<pre class="brush: js">var arr1 = [0, 1, 2]; var arr2 = [3, 4, 5]; var arr3 = [...arr1, ...arr2]; </pre> <p>{{jsxref("Array.unshift")}} 方法常用于在数组的开头插入新元素/数组. 不使用展开语法, 示例如下:</p> -<pre class="brush: js notranslate">var arr1 = [0, 1, 2]; +<pre class="brush: js">var arr1 = [0, 1, 2]; var arr2 = [3, 4, 5]; // 将 arr2 中的元素插入到 arr1 的开头 Array.prototype.unshift.apply(arr1, arr2) // arr1 现在是 [3, 4, 5, 0, 1, 2]</pre> <p>如果使用展开语法, 代码如下: [请注意, 这里使用展开语法创建了一个新的 <code>arr1</code> 数组, {{jsxref("Array.unshift")}} 方法则是修改了原本存在的 <code>arr1</code> 数组]:</p> -<pre class="brush: js notranslate">var arr1 = [0, 1, 2]; +<pre class="brush: js">var arr1 = [0, 1, 2]; var arr2 = [3, 4, 5]; arr1 = [...arr2, ...arr1]; // arr1 现在为 [3, 4, 5, 0, 1, 2] </pre> @@ -157,7 +157,7 @@ arr1 = [...arr2, ...arr1]; // arr1 现在为 [3, 4, 5, 0, 1, 2] <p>浅拷贝(Shallow-cloning, 不包含 prototype) 和对象合并, 可以使用更简短的展开语法。而不必再使用 {{jsxref("Object.assign()")}} 方式.</p> -<pre class="brush: js notranslate">var obj1 = { foo: 'bar', x: 42 }; +<pre class="brush: js">var obj1 = { foo: 'bar', x: 42 }; var obj2 = { foo: 'baz', y: 13 }; var clonedObj = { ...obj1 }; @@ -173,7 +173,7 @@ var mergedObj = { ...obj1, ...obj2 }; <p><strong>提示</strong>: 不能替换或者模拟 {{jsxref("Object.assign()")}} 函数:</p> -<pre class="notranslate"><code>var obj1 = { foo: 'bar', x: 42 }; +<pre><code>var obj1 = { foo: 'bar', x: 42 }; var obj2 = { foo: 'baz', y: 13 }; const merge = ( ...objects ) => ( { ...objects } ); @@ -191,7 +191,7 @@ var mergedObj = merge ( {}, obj1, obj2); <p>在数组或函数参数中使用展开语法时, 该语法只能用于 <a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator">可迭代对象</a>:</p> -<pre class="brush: js notranslate">var obj = {'key1': 'value1'}; +<pre class="brush: js">var obj = {'key1': 'value1'}; var array = [...obj]; // TypeError: obj is not iterable </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html index 125b67c168..1b8211841a 100644 --- a/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html +++ b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_equality <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">x === y</pre> +<pre class="syntaxbox">x === y</pre> <h2 id="描述">描述</h2> @@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_equality <h3 id="比较相同类型的操作数">比较相同类型的操作数</h3> -<pre class="brush: js notranslate">console.log("hello" === "hello"); // true +<pre class="brush: js">console.log("hello" === "hello"); // true console.log("hello" === "hola"); // false console.log(3 === 3); // true @@ -52,7 +52,7 @@ console.log(null === null); // true</pre> <h3 id="比较不同类型的操作数">比较不同类型的操作数</h3> -<pre class="brush: js notranslate">console.log("3" === 3); // false +<pre class="brush: js">console.log("3" === 3); // false console.log(true === 1); // false @@ -60,7 +60,7 @@ console.log(null === undefined); // false</pre> <h3 id="比较对象">比较对象</h3> -<pre class="brush: js notranslate">const object1 = { +<pre class="brush: js">const object1 = { name: "hello" } diff --git a/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html b/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html index a31aa575d1..26efd1748f 100644 --- a/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html +++ b/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html @@ -13,13 +13,13 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_inequality <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">x !== y</pre> +<pre class="syntaxbox">x !== y</pre> <h2 id="描述">描述</h2> <p>严格不等式运算符检查其对象是否不相等。它是严格相等运算符的否定,因此下面两行总是会给出相同的结果:</p> -<pre class="brush: js notranslate">x !== y +<pre class="brush: js">x !== y !(x === y)</pre> @@ -27,13 +27,13 @@ translation_of: Web/JavaScript/Reference/Operators/Strict_inequality <p>与严格相等运算符一样,严格不等运算符始终认为不同类型的对象是不同的:</p> -<pre class="brush: js notranslate">3 !== "3"; // true</pre> +<pre class="brush: js">3 !== "3"; // true</pre> <h2 id="示例">示例</h2> <h3 id="比较相同类型的对象">比较相同类型的对象</h3> -<pre class="brush: js notranslate">console.log("hello" !== "hello"); // false +<pre class="brush: js">console.log("hello" !== "hello"); // false console.log("hello" !== "hola"); // true console.log(3 !== 3); // false @@ -46,7 +46,7 @@ console.log(null !== null); // false</pre> <h3 id="比较不同类型的对象">比较不同类型的对象</h3> -<pre class="brush: js notranslate">console.log("3" !== 3); // true +<pre class="brush: js">console.log("3" !== 3); // true console.log(true !== 1); // true @@ -54,7 +54,7 @@ console.log(null !== undefined); // true</pre> <h3 id="比较Object对象">比较Object对象</h3> -<pre class="brush: js notranslate">const object1 = { +<pre class="brush: js">const object1 = { name: "hello" } diff --git a/files/zh-cn/web/javascript/reference/operators/subtraction/index.html b/files/zh-cn/web/javascript/reference/operators/subtraction/index.html index 00dcee2a1e..c4307e2ace 100644 --- a/files/zh-cn/web/javascript/reference/operators/subtraction/index.html +++ b/files/zh-cn/web/javascript/reference/operators/subtraction/index.html @@ -15,19 +15,19 @@ translation_of: Web/JavaScript/Reference/Operators/Subtraction <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> <var>x</var> - <var>y</var> +<pre class="syntaxbox"><strong>Operator:</strong> <var>x</var> - <var>y</var> </pre> <h2 id="Examples">Examples</h2> <h3 id="Subtraction_with_numbers">Subtraction with numbers</h3> -<pre class="brush: js notranslate">5 - 3 // 2 +<pre class="brush: js">5 - 3 // 2 3 - 5 // -2</pre> <h3 id="Subtraction_with_non-numbers">Subtraction with non-numbers</h3> -<pre class="brush: js notranslate">'foo' - 3 // NaN</pre> +<pre class="brush: js">'foo' - 3 // NaN</pre> <h2 id="Specifications">Specifications</h2> diff --git a/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html index 93dc5a138b..9d96a67f7e 100644 --- a/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/subtraction_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Subtraction_assignment <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x -= y +<pre class="syntaxbox"><strong>Operator:</strong> x -= y <strong>Meaning:</strong> x = x - y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_subtraction_assignment">Using subtraction assignment</h3> -<pre class="brush: js notranslate">// Assuming the following variable +<pre class="brush: js">// Assuming the following variable // bar = 5 bar -= 2 // 3 diff --git a/files/zh-cn/web/javascript/reference/operators/super/index.html b/files/zh-cn/web/javascript/reference/operators/super/index.html index 1f279cb42f..ba936e09ba 100644 --- a/files/zh-cn/web/javascript/reference/operators/super/index.html +++ b/files/zh-cn/web/javascript/reference/operators/super/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Operators/super <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">super([arguments]); +<pre class="syntaxbox">super([arguments]); // 调用 父对象/父类 的构造函数 super.functionOnParent([arguments]); @@ -33,7 +33,7 @@ super.functionOnParent([arguments]); <p>以下代码片段来自于 <a href="https://github.com/GoogleChrome/samples/blob/gh-pages/classes-es6/index.html">classes sample</a>。</p> -<pre class="brush: js notranslate">class Polygon { +<pre class="brush: js">class Polygon { constructor(height, width) { this.name = 'Rectangle'; this.height = height; @@ -69,7 +69,7 @@ class Square extends Polygon { <p>你也可以用 super 调用父类的<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static">静态方法</a>。</p> -<pre class="brush: js notranslate">class Rectangle { +<pre class="brush: js">class Rectangle { constructor() {} static logNbSides() { return 'I have 4 sides'; @@ -88,7 +88,7 @@ Square.logDescription(); // 'I have 4 sides which are all equal'</pre> <p>你不能使用 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete 操作符</a> 加 <code>super.prop</code> 或者 <code>super[expr]</code> 去删除父类的属性,这样做会抛出 {{jsxref("ReferenceError")}}。</p> -<pre class="brush: js notranslate">class Base { +<pre class="brush: js">class Base { constructor() {} foo() {} } @@ -105,7 +105,7 @@ new Derived().delete(); // ReferenceError: invalid delete involving 'super'.</pr <p>当使用 {{jsxref("Object.defineProperty")}} 定义一个属性为不可写时,<code>super</code>将不能重写这个属性的值。</p> -<pre class="brush: js notranslate">class X { +<pre class="brush: js">class X { constructor() { Object.defineProperty(this, 'prop', { configurable: true, @@ -132,7 +132,7 @@ console.log(y.prop); // 1</pre> <p><code>Super</code>也可以在<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">object initializer / literal</a> 符号中使用。在下面的例子中,两个对象各定义了一个方法。在第二个对象中, 我们使用<code>super</code>调用了第一个对象中的方法。 当然,这需要我们先利用 {{jsxref("Object.setPrototypeOf()")}} 设置<code>obj2</code>的原型为<code>obj1</code>,然后才能够使用<code>super</code>调用 <code>obj1</code>上的<code>method1</code>。</p> -<pre class="brush: js notranslate">var obj1 = { +<pre class="brush: js">var obj1 = { method1() { console.log("method 1"); } diff --git a/files/zh-cn/web/javascript/reference/operators/this/index.html b/files/zh-cn/web/javascript/reference/operators/this/index.html index aea931541f..86616407d0 100644 --- a/files/zh-cn/web/javascript/reference/operators/this/index.html +++ b/files/zh-cn/web/javascript/reference/operators/this/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/this <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate">this</pre> +<pre class="syntaxbox">this</pre> <h3 id="值">值</h3> @@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Operators/this <p>无论是否在严格模式下,在全局执行环境中(在任何函数体外部)<code>this</code> 都指向全局对象。</p> -<pre class="brush:js notranslate">// 在浏览器中, window 对象同时也是全局对象: +<pre class="brush:js">// 在浏览器中, window 对象同时也是全局对象: console.log(this === window); // true a = 37; @@ -52,7 +52,7 @@ console.log(b) // "MDN"</pre> <p>因为下面的代码不在严格模式下,且 <code>this</code> 的值不是由该调用设置的,所以 <code>this</code> 的值默认指向全局对象,浏览器中就是 {{domxref("Window", "window")}}。</p> -<pre class="brush:js notranslate">function f1(){ +<pre class="brush:js">function f1(){ return this; } //在浏览器中: @@ -64,7 +64,7 @@ f1() === globalThis; <p>然而,在严格模式下,如果进入执行环境时没有设置 <code>this</code> 的值,<code>this</code> 会保持为 <code>undefined</code>,如下:</p> -<pre class="brush:js notranslate">function f2(){ +<pre class="brush:js">function f2(){ "use strict"; // 这里是严格模式 return this; } @@ -82,7 +82,7 @@ f2() === undefined; // true <p>在类的构造函数中,<code>this</code> 是一个常规对象。类中所有非静态的方法都会被添加到 <code>this</code> 的原型中:</p> -<pre class="notranslate">class Example { +<pre>class Example { constructor() { const proto = Object.getPrototypeOf(this); console.log(Object.getOwnPropertyNames(proto)); @@ -102,7 +102,7 @@ new Example(); // ['constructor', 'first', 'second']</pre> <p>不像基类的构造函数,派生类的构造函数没有初始的 <code>this</code> 绑定。在构造函数中调用 {{jsxref("Operators/super", "super()")}} 会生成一个 <code>this</code> 绑定,并相当于执行如下代码,Base为基类:</p> -<pre class="notranslate">this = new Base();</pre> +<pre>this = new Base();</pre> <div class="blockIndicator warning"> <p><strong>警告:</strong>在调用 <code>super()</code> 之前引用 <code>this</code> 会抛出错误。</p> @@ -110,7 +110,7 @@ new Example(); // ['constructor', 'first', 'second']</pre> <p>派生类不能在调用 <code>super()</code> 之前返回,除非其构造函数返回的是一个对象,或者根本没有构造函数。</p> -<pre class="notranslate">class Base {} +<pre>class Base {} class Good extends Base {} class AlsoGood extends Base { constructor() { @@ -147,7 +147,7 @@ whatsThis.apply(obj); // 'Custom' 因为函数中的 this 被设置为obj <h3 id="this_和对象转换">this 和对象转换</h3> -<pre class="notranslate">function add(c, d) { +<pre>function add(c, d) { return this.a + this.b + c + d; } @@ -164,7 +164,7 @@ add.apply(o, [10, 20]); // 34 <p>在非严格模式下使用 <code>call</code> 和 <code>apply</code> 时,如果用作 <code>this</code> 的值不是对象,则会被尝试转换为对象。<code>null</code> 和 <code>undefined</code> 被转换为全局对象。原始值如 <code>7</code> 或 <code>'foo'</code> 会使用相应构造函数转换为对象。因此 <code>7</code> 会被转换为 <code>new Number(7)</code> 生成的对象,字符串 <code>'foo'</code> 会转换为 <code>new String('foo')</code> 生成的对象。</p> -<pre class="notranslate">function bar() { +<pre>function bar() { console.log(Object.prototype.toString.call(this)); } @@ -176,7 +176,7 @@ bar.call(undefined); // [object global]</pre> <p>ECMAScript 5 引入了 {{jsxref("Function.prototype.bind()")}}。调用<code>f.bind(someObject)</code>会创建一个与<code>f</code>具有相同函数体和作用域的函数,但是在这个新函数中,<code>this</code>将永久地被绑定到了<code>bind</code>的第一个参数,无论这个函数是如何被调用的。</p> -<pre class="brush:js notranslate">function f(){ +<pre class="brush:js">function f(){ return this.a; } @@ -194,7 +194,7 @@ console.log(o.a, o.f(), o.g(), o.h()); // 37, 37, azerty, azerty <p>在<a href="/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions">箭头函数</a>中,<code>this</code>与封闭词法环境的<code>this</code>保持一致。在全局代码中,它将被设置为全局对象:</p> -<pre class="brush: js notranslate">var globalObject = this; +<pre class="brush: js">var globalObject = this; var foo = (() => this); console.log(foo() === globalObject); // true</pre> @@ -202,7 +202,7 @@ console.log(foo() === globalObject); // true</pre> <p>注意:如果将<code>this</code>传递给<code>call</code>、<code>bind</code>、或者<code>apply</code>来调用箭头函数,它将被忽略。不过你仍然可以为调用添加参数,不过第一个参数(<code>thisArg</code>)应该设置为<code>null</code>。</p> </div> -<pre class="brush: js notranslate">// 接着上面的代码 +<pre class="brush: js">// 接着上面的代码 // 作为对象的一个方法调用 var obj = {foo: foo}; console.log(obj.foo() === globalObject); // true @@ -216,7 +216,7 @@ console.log(foo() === globalObject); // true</pre> <p>无论如何,<code>foo</code> 的 <code>this</code> 被设置为他被创建时的环境(在上面的例子中,就是全局对象)。这同样适用于在其他函数内创建的箭头函数:这些箭头函数的<code>this</code>被设置为封闭的词法环境的。</p> -<pre class="brush: js notranslate">// 创建一个含有bar方法的obj对象, +<pre class="brush: js">// 创建一个含有bar方法的obj对象, // bar返回一个函数, // 这个函数返回this, // 这个返回的函数是以箭头函数创建的, @@ -252,7 +252,7 @@ console.log(fn2()() == window); // true</pre> <p>下面的例子中,当 <code>o.f()</code> 被调用时,函数内的 <code>this</code> 将绑定到 <code>o</code> 对象。</p> -<pre class="brush:js notranslate">var o = { +<pre class="brush:js">var o = { prop: 37, f: function() { return this.prop; @@ -264,7 +264,7 @@ console.log(o.f()); // 37 <p>请注意,这样的行为完全不会受函数定义方式或位置的影响。在前面的例子中,我们在定义对象<code>o</code>的同时,将其中的函数定义为成员 <code>f</code> 。但是,我们也可以先定义函数,然后再将其附属到<code>o.f</code>。这样做的结果是一样的:</p> -<pre class="brush:js notranslate">var o = {prop: 37}; +<pre class="brush:js">var o = {prop: 37}; function independent() { return this.prop; @@ -279,14 +279,14 @@ console.log(o.f()); // 37 <p>同样,<code>this</code> 的绑定只受最接近的成员引用的影响。在下面的这个例子中,我们把一个方法<code>g</code>当作对象<code>o.b</code>的函数调用。在这次执行期间,函数中的<code>this</code>将指向<code>o.b</code>。事实证明,这与他是对象 <code>o</code> 的成员没有多大关系,最近的引用才是最重要的。</p> -<pre class="brush: js notranslate"><code>o.b = {g: independent, prop: 42}; +<pre class="brush: js"><code>o.b = {g: independent, prop: 42}; console.log(o.b.g()); // 42</code></pre> <h4 id="原型链中的_this">原型链中的 <code><strong>this</strong></code></h4> <p>对于在对象原型链上某处定义的方法,同样的概念也适用。如果该方法存在于一个对象的原型链上,那么 <code>this</code> 指向的是调用这个方法的对象,就像该方法就在这个对象上一样。</p> -<pre class="brush:js notranslate">var o = { +<pre class="brush:js">var o = { f: function() { return this.a + this.b; } @@ -304,7 +304,7 @@ console.log(p.f()); // 5 <p>再次,相同的概念也适用于当函数在一个 <code>getter</code> 或者 <code>setter</code> 中被调用。用作 <code>getter</code> 或 <code>setter</code> 的函数都会把 <code>this</code> 绑定到设置或获取属性的对象。</p> -<pre class="brush: js notranslate">function sum() { +<pre class="brush: js">function sum() { return this.a + this.b + this.c; } @@ -331,7 +331,7 @@ console.log(o.average, o.sum); // logs 2, 6 <p>虽然构造函数返回的默认值是 <code>this</code> 所指的那个对象,但它仍可以手动返回其他的对象(如果返回值不是一个对象,则返回 <code>this</code> 对象)。</p> </div> -<pre class="brush: js notranslate">/* +<pre class="brush: js">/* * 构造函数这样工作: * * function MyConstructor(){ @@ -370,7 +370,7 @@ console.log(o.a); // logs 38 <p>当函数被用作事件处理函数时,它的 <code>this</code> 指向触发事件的元素(一些浏览器在使用非 <code>addEventListener</code> 的函数动态地添加监听函数时不遵守这个约定)。</p> -<pre class="brush:js notranslate">// 被调用时,将关联的元素变成蓝色 +<pre class="brush:js">// 被调用时,将关联的元素变成蓝色 function bluify(e){ console.log(this === e.currentTarget); // 总是 true @@ -391,14 +391,14 @@ for(var i=0 ; i<elements.length ; i++){ <p>当代码被内联 <a href="/zh-CN/docs/Web/Guide/Events/Event_handlers">on-event 处理函数</a> 调用时,它的<code>this</code>指向监听器所在的DOM元素:</p> -<pre class="brush: html notranslate"><button onclick="alert(this.tagName.toLowerCase());"> +<pre class="brush: html"><button onclick="alert(this.tagName.toLowerCase());"> Show this </button> </pre> <p>上面的 alert 会显示 <code>button</code>。注意只有外层代码中的 <code>this</code> 是这样设置的:</p> -<pre class="brush: html notranslate"><button onclick="alert((function(){return this})());"> +<pre class="brush: html"><button onclick="alert((function(){return this})());"> Show inner this </button> </pre> @@ -409,7 +409,7 @@ for(var i=0 ; i<elements.length ; i++){ <p>和其他普通函数一样,方法中的 <code>this</code> 值取决于它们如何被调用。有时,改写这个行为,让类中的 <code>this</code> 值总是指向这个类实例会很有用。为了做到这一点,可在构造函数中绑定类方法:</p> -<pre class="notranslate">class Car { +<pre>class Car { constructor() { // Bind sayBye but not sayHi to show the difference this.sayBye = this.sayBye.bind(this); diff --git a/files/zh-cn/web/javascript/reference/operators/typeof/index.html b/files/zh-cn/web/javascript/reference/operators/typeof/index.html index 41cf3c8da9..60cd51b992 100644 --- a/files/zh-cn/web/javascript/reference/operators/typeof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/typeof/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/typeof <p><code>typeof</code> 运算符后接操作数:</p> -<pre class="syntaxbox notranslate">typeof <em>operand +<pre class="syntaxbox">typeof <em>operand typeof(operand)</em> </pre> @@ -88,7 +88,7 @@ typeof(operand)</em> <h2 id="示例">示例</h2> -<pre class="brush: js notranslate">// 数值 +<pre class="brush: js">// 数值 typeof 37 === 'number'; typeof 3.14 === 'number'; typeof(42) === 'number'; @@ -152,7 +152,7 @@ typeof Math.sin === 'function'; <h3 id="typeof_null"><code>typeof null</code></h3> -<pre class="brush: js notranslate"><code>// JavaScript 诞生以来便如此 +<pre class="brush: js"><code>// JavaScript 诞生以来便如此 typeof null === 'object';</code></pre> <p>在 JavaScript 最初的实现中,JavaScript 中的值是由一个表示类型的标签和实际数据值表示的。对象的类型标签是 0。由于 <code>null</code> 代表的是空指针(大多数平台下值为 0x00),因此,null 的类型标签是 0,<code>typeof null</code> 也因此返回 <code>"object"</code>。(<a href="http://www.2ality.com/2013/10/typeof-null.html">参考来源</a>)</p> @@ -161,7 +161,7 @@ typeof null === 'object';</code></pre> <h3 id="使用_new_操作符">使用 <code>new</code> 操作符</h3> -<pre class="brush: js notranslate">// 除 Function 外的所有构造函数的类型都是 'object' +<pre class="brush: js">// 除 Function 外的所有构造函数的类型都是 'object' var str = new String('String'); var num = new Number(100); @@ -174,7 +174,7 @@ typeof func; // 返回 'function'</pre> <h3 id="语法中的括号">语法中的括号</h3> -<pre class="brush: js notranslate">// 括号有无将决定表达式的类型。 +<pre class="brush: js">// 括号有无将决定表达式的类型。 var iData = 99; typeof iData + ' Wisen'; // 'number Wisen' @@ -184,7 +184,7 @@ typeof (iData + ' Wisen'); // 'string'</pre> <p>对正则表达式字面量的类型判断在某些浏览器中不符合标准:</p> -<pre class="brush: js notranslate">typeof /s/ === 'function'; // Chrome 1-12 , 不符合 ECMAScript 5.1 +<pre class="brush: js">typeof /s/ === 'function'; // Chrome 1-12 , 不符合 ECMAScript 5.1 typeof /s/ === 'object'; // Firefox 5+ , 符合 ECMAScript 5.1 </pre> @@ -194,7 +194,7 @@ typeof /s/ === 'object'; // Firefox 5+ , 符合 ECMAScript 5.1 <p>但在加入了块级作用域的 <a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/let">let</a> 和 <a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/const">const</a> 之后,在其被声明之前对块中的 <code>let</code> 和 <code>const</code> 变量使用 <code>typeof</code> 会抛出一个 <a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError">ReferenceError</a>。块作用域变量在块的头部处于“<a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/let#Temporal_Dead_Zone_and_errors_with_let">暂存死区</a>”,直至其被初始化,在这期间,访问变量将会引发错误。</p> -<pre class="brush: js notranslate">typeof undeclaredVariable === 'undefined'; +<pre class="brush: js">typeof undeclaredVariable === 'undefined'; typeof newLetVariable; // ReferenceError typeof newConstVariable; // ReferenceError @@ -208,7 +208,7 @@ class newClass{};</pre> <p>当前所有的浏览器都暴露了一个类型为 <code>undefined</code> 的非标准宿主对象 {{domxref("document.all")}}。</p> -<pre class="brush: js notranslate">typeof document.all === 'undefined'; +<pre class="brush: js">typeof document.all === 'undefined'; </pre> <p>尽管规范允许为非标准的外来对象自定义类型标签,但它要求这些类型标签与已有的不同。<code>document.all</code> 的类型标签为 <code>'undefined'</code> 的例子在 Web 领域中被归类为对原 ECMA JavaScript 标准的“故意侵犯”。</p> @@ -219,7 +219,7 @@ class newClass{};</pre> <p>For greater specificity in checking types, a <code>typeof</code> wrapper for usage in production-level code would be as follows (provided <code>obj</code> exists):</p> -<pre class="brush: js notranslate"> function type(obj, fullClass) { +<pre class="brush: js"> function type(obj, fullClass) { // get toPrototypeString() of obj (handles all types) // Early JS environments return '[object Object]' for null, so it's best to directly check for it. @@ -265,7 +265,7 @@ class newClass{};</pre> <p>在 IE 6, 7 和 8 上,很多宿主对象是对象而不是函数。例如:</p> -<pre class="brush: js notranslate">typeof alert === 'object'</pre> +<pre class="brush: js">typeof alert === 'object'</pre> </div> <div class="brush:js language-js line-number" style=""></div> diff --git a/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html b/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html index 2170b92c53..887a79a2a0 100644 --- a/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unary_negation/index.html @@ -13,14 +13,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_negation <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> -<var>x</var> +<pre class="syntaxbox"><strong>Operator:</strong> -<var>x</var> </pre> <h2 id="Examples">Examples</h2> <h3 id="Negating_numbers">Negating numbers</h3> -<pre class="brush: js notranslate">const x = 3; +<pre class="brush: js">const x = 3; const y = -x; // y = -3 @@ -31,7 +31,7 @@ const y = -x; <p>The unary negation operator can convert a non-number into a number.</p> -<pre class="brush: js notranslate">const x = "4"; +<pre class="brush: js">const x = "4"; const y = -x; // y = -4 diff --git a/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html b/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html index 9f3b818df9..da09fa1f02 100644 --- a/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unary_plus/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_plus <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> +<var>x</var> +<pre class="syntaxbox"><strong>Operator:</strong> +<var>x</var> </pre> <h2 id="Description">Description</h2> @@ -24,7 +24,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unary_plus <h3 id="Usage_with_numbers">Usage with numbers</h3> -<pre class="brush: js notranslate">const x = 1; +<pre class="brush: js">const x = 1; const y = -1; console.log(+x); @@ -34,7 +34,7 @@ console.log(+y); <h3 id="Usage_with_non-numbers">Usage with non-numbers</h3> -<pre class="brush: js notranslate">+true // 1 +<pre class="brush: js">+true // 1 +false // 0 +null // 0 +function(val){ return val } // NaN diff --git a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html index f40a28e8b0..52f18ea92c 100644 --- a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><code><var>a</var> >>> <var>b</var></code> +<pre class="syntaxbox"><code><var>a</var> >>> <var>b</var></code> </pre> <h2 id="描述">描述</h2> @@ -22,14 +22,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift <p>For non-negative numbers, zero-fill right shift and sign-propagating right shift yield the same result. For example, <code>9 >>> 2</code> yields 2, the same as <code>9 >> 2</code>:</p> -<pre class="brush: js notranslate">. 9 (base 10): 00000000000000000000000000001001 (base 2) +<pre class="brush: js">. 9 (base 10): 00000000000000000000000000001001 (base 2) -------------------------------- 9 >>> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10) </pre> <p>However, this is not the case for negative numbers. For example, <code>-9 >>> 2</code> yields 1073741821, which is different than <code>-9 >> 2</code> (which yields <code>-3</code>):</p> -<pre class="brush: js notranslate">. -9 (base 10): 11111111111111111111111111110111 (base 2) +<pre class="brush: js">. -9 (base 10): 11111111111111111111111111110111 (base 2) -------------------------------- -9 >>> 2 (base 10): 00111111111111111111111111111101 (base 2) = 1073741821 (base 10) </pre> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift <h3 id="Using_unsigned_right_shift">Using unsigned right shift</h3> -<pre class="brush: js notranslate"> 9 >>> 2; // 2 +<pre class="brush: js"> 9 >>> 2; // 2 -9 >>> 2; // 1073741821 </pre> diff --git a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html index 76379358c0..0c2e1fb3c5 100644 --- a/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/unsigned_right_shift_assignment/index.html @@ -15,14 +15,14 @@ translation_of: Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignme <h2 id="语法">语法</h2> -<pre class="syntaxbox notranslate"><strong>Operator:</strong> x >>>= y +<pre class="syntaxbox"><strong>Operator:</strong> x >>>= y <strong>Meaning:</strong> x = x >>> y</pre> <h2 id="例子">例子</h2> <h3 id="Using_unsigned_right_shift_assignment">Using unsigned right shift assignment</h3> -<pre class="brush: js notranslate">let a = 5; // (00000000000000000000000000000101) +<pre class="brush: js">let a = 5; // (00000000000000000000000000000101) a >>>= 2; // 1 (00000000000000000000000000000001) let b = -5; // (-00000000000000000000000000000101) |