From d44f5032d0f53256b2d5aef505d6b593fd3cd158 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:14:18 +0800 Subject: fix yari h2m dry run errors (zh-CN) --- .../reference/operators/await/index.html | 54 +--------------------- .../reference/operators/bitwise_and/index.html | 6 +-- .../reference/operators/bitwise_not/index.html | 4 +- .../reference/operators/bitwise_or/index.html | 6 +-- .../reference/operators/bitwise_xor/index.html | 6 +-- .../reference/operators/comma_operator/index.html | 2 +- .../operators/conditional_operator/index.html | 2 +- .../reference/operators/delete/index.html | 4 +- .../operators/destructuring_assignment/index.html | 4 +- .../reference/operators/function/index.html | 50 +------------------- .../web/javascript/reference/operators/index.html | 8 ++-- .../reference/operators/instanceof/index.html | 8 +++- .../reference/operators/logical_or/index.html | 4 +- .../javascript/reference/operators/new/index.html | 2 +- .../operators/optional_chaining/index.html | 8 ++-- .../operators/property_accessors/index.html | 2 +- .../javascript/reference/operators/this/index.html | 22 +++++---- .../reference/operators/typeof/index.html | 6 +-- 18 files changed, 51 insertions(+), 147 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/operators') 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 4f0ea9b0c3..463f0e8ea1 100644 --- a/files/zh-cn/web/javascript/reference/operators/await/index.html +++ b/files/zh-cn/web/javascript/reference/operators/await/index.html @@ -95,59 +95,7 @@ f3();

浏览器兼容性

-
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerEdgeOperaSafari (WebKit)
基本支持{{CompatChrome(55)}}{{CompatGeckoDesktop("52.0")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(42)}}{{CompatUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
 基本支持{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("52.0")}}{{CompatUnknown}}{{CompatOpera(42)}}{{CompatUnknown}}{{CompatChrome(55)}}
-
+{{Compat}}

查看更多

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 017d0d464c..28489e61a3 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 @@ -31,9 +31,9 @@ After: 10100000000000000110000000000001 - - - + + + 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 46ffd369dd..8cd674a8cb 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 @@ -38,8 +38,8 @@ After: 10100000000000000110000000000001
aba AND baba AND b
- - + + 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 2f83d5d956..5c5810d152 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 @@ -30,9 +30,9 @@ After: 10100000000000000110000000000001
aNOT aaNOT a
- - - + + + 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 1ec5d48f0a..9b670f4a58 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 @@ -30,9 +30,9 @@ After: 10100000000000000110000000000001
aba OR baba OR b
- - - + + + diff --git a/files/zh-cn/web/javascript/reference/operators/comma_operator/index.html b/files/zh-cn/web/javascript/reference/operators/comma_operator/index.html index cc7b2f83a8..1c9ca88054 100644 --- a/files/zh-cn/web/javascript/reference/operators/comma_operator/index.html +++ b/files/zh-cn/web/javascript/reference/operators/comma_operator/index.html @@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Operators/Comma_Operator

假设 a 是一个二维数组,每一维度包含10个元素,则下面的代码使用逗号操作符一次递增/递减两个变量。需要注意的是,var 语句中的逗号不是逗号操作符,因为它不是存在于一个表达式中。尽管从实际效果来看,那个逗号同逗号运算符的表现很相似。但确切地说,它是 var 语句中的一个特殊符号,用于把多个变量声明结合成一个。下面的代码打印一个二维数组中斜线方向的元素:

-
for (var i = 0, j = 9; i <= 9; i++, j--)
+
for (var i = 0, j = 9; i <= 9; i++, j--)
   document.writeln("a[" + i + "][" + j + "] = " + a[i][j]);

处理后返回

diff --git a/files/zh-cn/web/javascript/reference/operators/conditional_operator/index.html b/files/zh-cn/web/javascript/reference/operators/conditional_operator/index.html index cb3153c5ee..720dda3c68 100644 --- a/files/zh-cn/web/javascript/reference/operators/conditional_operator/index.html +++ b/files/zh-cn/web/javascript/reference/operators/conditional_operator/index.html @@ -52,7 +52,7 @@ console.log(greeting({name: 'Alice'})); // "Howdy, Alice" console.log(greeting(null)); // "Howdy, stranger"
-
+

Note: The optional chaining operator 设计用来处理这种使用场景。在本文档写成的时候 (2019.01),这个运算符还处于实验阶段并且没有实现。

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 f8b4e02e0c..f061e72ba2 100644 --- a/files/zh-cn/web/javascript/reference/operators/delete/index.html +++ b/files/zh-cn/web/javascript/reference/operators/delete/index.html @@ -131,8 +131,8 @@ console.log(delete variable2); // false console.log(delete func); // false -
-

下文在英文原版中已删除

+
+

备注:下文在英文原版中已删除

任何使用var声明的变量都会被标记为不可设置的。在下面的例子中,salary是不可设置的以及不能被删除的。在非严格模式下,下面的delete操作将会返回false。

diff --git a/files/zh-cn/web/javascript/reference/operators/destructuring_assignment/index.html b/files/zh-cn/web/javascript/reference/operators/destructuring_assignment/index.html index 93182a3253..05cc98f3a9 100644 --- a/files/zh-cn/web/javascript/reference/operators/destructuring_assignment/index.html +++ b/files/zh-cn/web/javascript/reference/operators/destructuring_assignment/index.html @@ -188,7 +188,7 @@ console.log(q); // true
-

注意:赋值语句周围的圆括号 ( ... ) 在使用对象字面量无声明解构赋值时是必须的。

+

备注:赋值语句周围的圆括号 ( ... ) 在使用对象字面量无声明解构赋值时是必须的。

{a, b} = {a: 1, b: 2} 不是有效的独立语法,因为左边的 {a, b} 被认为是一个块而不是对象字面量。

@@ -259,7 +259,7 @@ drawES2015Chart({ });
-

在上面的 drawES2015Chart 的函数签名中,解构的左手边被分配给右手边的空对象字面值:{size = 'big', cords = {x: 0, y: 0}, radius = 25} = {}。你也可以在没有右侧分配的情况下编写函数。但是,如果你忽略了右边的赋值,那么函数会在被调用的时候查找至少一个被提供的参数,而在当前的形式下,你可以直接调用 drawES2015Chart() 而不提供任何参数。如果你希望能够在不提供任何参数的情况下调用该函数,则当前的设计非常有用,而另一种方法在您确保将对象传递给函数时非常有用。

+

备注:在上面的 drawES2015Chart 的函数签名中,解构的左手边被分配给右手边的空对象字面值:{size = 'big', cords = {x: 0, y: 0}, radius = 25} = {}。你也可以在没有右侧分配的情况下编写函数。但是,如果你忽略了右边的赋值,那么函数会在被调用的时候查找至少一个被提供的参数,而在当前的形式下,你可以直接调用 drawES2015Chart() 而不提供任何参数。如果你希望能够在不提供任何参数的情况下调用该函数,则当前的设计非常有用,而另一种方法在您确保将对象传递给函数时非常有用。

解构嵌套对象和数组

diff --git a/files/zh-cn/web/javascript/reference/operators/function/index.html b/files/zh-cn/web/javascript/reference/operators/function/index.html index c3c9bd85ea..5a69175075 100644 --- a/files/zh-cn/web/javascript/reference/operators/function/index.html +++ b/files/zh-cn/web/javascript/reference/operators/function/index.html @@ -120,55 +120,7 @@ console.log(bar === baz); // false (errors because baz == undefined)

浏览器兼容性

-

{{ CompatibilityTable() }}

- -
-
aba XOR baba XOR b
- - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
- - -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
-
+{{Compat}}

相关链接

diff --git a/files/zh-cn/web/javascript/reference/operators/index.html b/files/zh-cn/web/javascript/reference/operators/index.html index 810ccb74cd..82ff728c29 100644 --- a/files/zh-cn/web/javascript/reference/operators/index.html +++ b/files/zh-cn/web/javascript/reference/operators/index.html @@ -135,7 +135,9 @@ translation_of: Web/JavaScript/Reference/Operators
大于等于运算符。 
-
注意: => 不是运算符,而是{{jsxref("Functions/Arrow_functions", "箭头函数")}}的表示符。
+
+

备注: 不是运算符,而是{{jsxref("Functions/Arrow_functions", "箭头函数")}}的表示符。

+

相等运算符

@@ -241,11 +243,11 @@ translation_of: Web/JavaScript/Reference/Operators

解构赋值允许你分配数组或者对象变量的属性通过使用规定的语法,其看起来和数组和对象字面量很相似。

-

逗号操作符 {{jsxref("Operators/Comma_Operator", ",")}}

+ 逗号操作符 {{jsxref("Operators/Comma_Operator", ",")}}
逗号操作符允许在一个判断状态中有多个表达式去进行运算并且最后返回最后一个表达式的值。
-

非标准化特性 {{JSxRef("Operators/Expression_closures", "Expression closures", "", 1)}} {{non-standard_inline}}{{obsolete_inline(60)}}

+ 非标准化特性 {{JSxRef("Operators/Expression_closures", "Expression closures", "", 1)}} {{non-standard_inline}}{{obsolete_inline(60)}}
闭包表达式语法是一个缩写简单的函数。
{{JSxRef("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}} {{non-standard_inline}}{{obsolete_inline(58)}}
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 f6f1f188f8..bb93a7028e 100644 --- a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html @@ -73,8 +73,12 @@ o3 instanceof C; // true 因为 C.prototype 现在在 o3 的原型链上

比如检测一个 Nodes 在另一个窗口中是不是 SVGElement,你可以使用myNode instanceof myNode.ownerDocument.defaultView.SVGElement

-
Mozilla开发者注意:
-在代码中使用 XPCOM instanceof 有特殊影响: 如果查询接口成功执行后,obj instanceof xpcomInterface (e.g. Components.interfaces.nsIFile) 调用obj.QueryInterface(xpcomInterface) 并且返回 true 。这种调用的副作用是在一次成功的 instanceof 测试后,你可以在 obj 上使用xpcomInterface 的属性。这与标准的 JavaScript 全局变量不同,即使 obj 来自不同的作用域,obj instanceof xpcomInterface 也可以按预期产生作用。
+
+

+ 备注: + 在代码中使用 XPCOM instanceof 有特殊影响: 如果查询接口成功执行后,obj instanceof xpcomInterface (e.g. Components.interfaces.nsIFile) 调用obj.QueryInterface(xpcomInterface) 并且返回 true 。这种调用的副作用是在一次成功的 instanceof 测试后,你可以在 obj 上使用xpcomInterface 的属性。这与标准的 JavaScript 全局变量不同,即使 obj 来自不同的作用域,obj instanceof xpcomInterface 也可以按预期产生作用。 +

+

示例

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 d159e76866..69f521ca62 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 @@ -73,8 +73,8 @@ o9 = false || '' // f || f returns "" o10 = false || varObject // f || object returns varObject -
-

Note: If you use this operator to provide a default value to some variable, be aware that any falsy value will not be used. If you only need to filter out {{jsxref("null")}} or {{jsxref("undefined")}}, consider using the nullish coalescing operator.

+
+

备注: If you use this operator to provide a default value to some variable, be aware that any falsy value will not be used. If you only need to filter out {{jsxref("null")}} or {{jsxref("undefined")}}, consider using the nullish coalescing operator.

Conversion rules for booleans

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 e44beb9763..4959409c31 100644 --- a/files/zh-cn/web/javascript/reference/operators/new/index.html +++ b/files/zh-cn/web/javascript/reference/operators/new/index.html @@ -83,7 +83,7 @@ console.log(car2.color) // original color
-

如果你没有使用 new 运算符, 构造函数会像其他的常规函数一样被调用,不会创建一个对象在这种情况下, this 的指向也是不一样的。

+

备注:如果你没有使用 new 运算符, 构造函数会像其他的常规函数一样被调用,不会创建一个对象在这种情况下, this 的指向也是不一样的。

示例

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 e765e6d66b..9c3f743c8a 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 @@ -61,12 +61,12 @@ let nestedProp = ((temp === null || temp === undefined) ? undefined : temp.secon
let result = someInterface.customMethod?.();
-
-

注意: 如果存在一个属性名且不是函数, 使用 ?. 仍然会产生一个 {{JSxRef("TypeError")}} 异常 (x.y is not a function).

+
+

备注:如果存在一个属性名且不是函数, 使用 ?. 仍然会产生一个 {{JSxRef("TypeError")}} 异常 (x.y is not a function).

-
-

注意: 如果 someInterface 自身是 null 或者 undefined ,异常 {{JSxRef("TypeError")}} 仍会被抛出 someInterface is null 如果你希望允许 someInterface 也为 null 或者 undefined ,那么你需要像这样写 someInterface?.customMethod?.()

+
+

备注:如果 someInterface 自身是 null 或者 undefined ,异常 {{JSxRef("TypeError")}} 仍会被抛出 someInterface is null 如果你希望允许 someInterface 也为 null 或者 undefined ,那么你需要像这样写 someInterface?.customMethod?.()

处理可选的回调函数或者事件处理器

diff --git a/files/zh-cn/web/javascript/reference/operators/property_accessors/index.html b/files/zh-cn/web/javascript/reference/operators/property_accessors/index.html index c7c482256d..6d139479f9 100644 --- a/files/zh-cn/web/javascript/reference/operators/property_accessors/index.html +++ b/files/zh-cn/web/javascript/reference/operators/property_accessors/index.html @@ -23,7 +23,7 @@ object['property']

描述

-

我们可以将对象看做是一个关联数组(或者:映射字典哈希表查询表)。这个数组中的键就是这个对象中属性的名称。通常,当我们提及一个对象的属性时,会对属性与方法之间做个对比。然而,属性与方法之间的区别并不大。一个方法就是一个可以被调用的属性而已,例如一个指向函数 Function 实例的引用可以作为对象属性的值。

+

我们可以将对象看做是一个关联数组(或者:映射字典哈希表查询表)。这个数组中的键就是这个对象中属性的名称。通常,当我们提及一个对象的属性时,会对属性与方法之间做个对比。然而,属性与方法之间的区别并不大。一个方法就是一个可以被调用的属性而已,例如一个指向函数 Function 实例的引用可以作为对象属性的值。

访问对象属性有两种方式:点号表示法和方括号表示法。

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 86616407d0..8e79b0d0d5 100644 --- a/files/zh-cn/web/javascript/reference/operators/this/index.html +++ b/files/zh-cn/web/javascript/reference/operators/this/index.html @@ -42,8 +42,8 @@ this.b = "MDN"; console.log(window.b) // "MDN" console.log(b) // "MDN" -
-

Note: 你可以使用 {{jsxref("globalThis")}} 获取全局对象,无论你的代码是否在当前上下文运行。

+
+

备注:你可以使用 {{jsxref("globalThis")}} 获取全局对象,无论你的代码是否在当前上下文运行。

函数上下文

@@ -72,7 +72,9 @@ f1() === globalThis; f2() === undefined; // true -
在第二个例子中,this 应是 undefined,因为 f2 是被直接调用的,而不是作为对象的属性或方法调用的(如 window.f2())。有一些浏览器最初在支持严格模式时没有正确实现这个功能,于是它们错误地返回了window对象。
+
+

备注:在第二个例子中,this 应是 undefined,因为 f2 是被直接调用的,而不是作为对象的属性或方法调用的(如 window.f2())。有一些浏览器最初在支持严格模式时没有正确实现这个功能,于是它们错误地返回了window对象。

+

如果要想把 this 的值从一个环境传到另一个,就要用 call 或者apply 方法,如下方的示例所示。

@@ -94,8 +96,8 @@ f2() === undefined; // true new Example(); // ['constructor', 'first', 'second'] -
-

注意:静态方法不是 this 的属性,它们只是类自身的属性。

+
+

备注:静态方法不是 this 的属性,它们只是类自身的属性。

派生类

@@ -104,7 +106,7 @@ new Example(); // ['constructor', 'first', 'second']
this = new Base();
-
+

警告:在调用 super() 之前引用 this 会抛出错误。

@@ -199,7 +201,7 @@ var foo = (() => this); console.log(foo() === globalObject); // true
-

注意:如果将this传递给callbind、或者apply来调用箭头函数,它将被忽略。不过你仍然可以为调用添加参数,不过第一个参数(thisArg)应该设置为null

+

备注:如果将this传递给callbind、或者apply来调用箭头函数,它将被忽略。不过你仍然可以为调用添加参数,不过第一个参数(thisArg)应该设置为null

// 接着上面的代码
@@ -328,7 +330,7 @@ console.log(o.average, o.sum); // logs 2, 6
 

当一个函数用作构造函数时(使用new关键字),它的this被绑定到正在构造的新对象。

-

虽然构造函数返回的默认值是 this 所指的那个对象,但它仍可以手动返回其他的对象(如果返回值不是一个对象,则返回 this 对象)。

+

备注:虽然构造函数返回的默认值是 this 所指的那个对象,但它仍可以手动返回其他的对象(如果返回值不是一个对象,则返回 this 对象)。

/*
@@ -443,8 +445,8 @@ bird.sayHi(); // Hello from Tweety
 bird.sayBye = car.sayBye;
 bird.sayBye();  // Bye from Ferrari
-
-

注意:类内部总是严格模式。调用一个 this 值为 undefined 的方法会抛出错误。

+
+

备注:类内部总是严格模式。调用一个 this 值为 undefined 的方法会抛出错误。

规范

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 ae77ab6261..1a149d5ed6 100644 --- a/files/zh-cn/web/javascript/reference/operators/typeof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/typeof/index.html @@ -27,9 +27,7 @@ typeof(operand)

operand

-
-
一个表示对象或{{Glossary("Primitive", "原始值")}}的表达式,其类型将被返回。
-
+

一个表示对象或{{Glossary("Primitive", "原始值")}}的表达式,其类型将被返回。

描述

@@ -268,8 +266,6 @@ class newClass{};
typeof alert === 'object'
-
-

相关链接

    -- cgit v1.2.3-54-g00ecf