From 012ee621791b6895e637f96e6523027951768f25 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:03:27 +0800 Subject: remove inline style for zh-CN --- files/zh-cn/web/javascript/closures/index.html | 12 +- .../index.html | 18 +- .../equality_comparisons_and_sameness/index.html | 236 ++++++++--------- .../control_flow_and_error_handling/index.html | 2 - .../guide/details_of_the_object_model/index.html | 4 +- .../guide/expressions_and_operators/index.html | 10 +- .../web/javascript/guide/functions/index.html | 2 +- .../guide/indexed_collections/index.html | 2 +- .../guide/regular_expressions/index.html | 16 +- .../guide/working_with_objects/index.html | 24 +- .../inheritance_and_the_prototype_chain/index.html | 294 ++++++++++----------- .../javascript_technologies_overview/index.html | 2 +- .../reference/classes/extends/index.html | 2 +- .../functions/arguments/callee/index.html | 2 +- .../reference/functions/arguments/index.html | 4 +- .../reference/global_objects/array/fill/index.html | 2 +- .../global_objects/array/findindex/index.html | 2 +- .../reference/global_objects/array/map/index.html | 2 +- .../reference/global_objects/array/of/index.html | 4 +- .../reference/global_objects/array/pop/index.html | 2 +- .../reference/global_objects/array/push/index.html | 4 +- .../global_objects/array/reduce/index.html | 7 - .../global_objects/array/reduceright/index.html | 4 +- .../global_objects/array/reverse/index.html | 16 +- .../global_objects/array/slice/index.html | 6 +- .../reference/global_objects/array/some/index.html | 2 +- .../global_objects/bigint64array/index.html | 2 +- .../global_objects/date/getdate/index.html | 12 +- .../global_objects/date/getday/index.html | 10 +- .../global_objects/date/getfullyear/index.html | 8 +- .../global_objects/date/gethours/index.html | 10 +- .../global_objects/date/getmilliseconds/index.html | 10 +- .../global_objects/date/getminutes/index.html | 10 +- .../global_objects/date/getmonth/index.html | 2 +- .../global_objects/date/getseconds/index.html | 14 +- .../date/gettimezoneoffset/index.html | 2 +- .../reference/global_objects/date/index.html | 2 +- .../global_objects/date/setfullyear/index.html | 4 +- .../global_objects/date/tolocalestring/index.html | 10 +- .../date/tolocaletimestring/index.html | 10 +- .../global_objects/date/totimestring/index.html | 2 +- .../reference/global_objects/error/index.html | 66 ++--- .../reference/global_objects/error/name/index.html | 48 ++-- .../global_objects/error/stack/index.html | 2 +- .../global_objects/function/apply/index.html | 12 +- .../global_objects/function/bind/index.html | 2 +- .../global_objects/function/call/index.html | 6 +- .../global_objects/function/name/index.html | 2 +- .../global_objects/function/tostring/index.html | 2 +- .../reference/global_objects/generator/index.html | 2 +- .../reference/global_objects/isfinite/index.html | 30 +-- .../reference/global_objects/json/index.html | 2 +- .../reference/global_objects/math/clz32/index.html | 2 +- .../reference/global_objects/math/expm1/index.html | 2 +- .../reference/global_objects/math/log/index.html | 34 +-- .../reference/global_objects/math/log1p/index.html | 4 +- .../reference/global_objects/math/pi/index.html | 2 +- .../reference/global_objects/math/pow/index.html | 2 +- .../reference/global_objects/math/round/index.html | 32 +-- .../reference/global_objects/math/sqrt2/index.html | 32 +-- .../reference/global_objects/math/trunc/index.html | 2 +- .../reference/global_objects/nan/index.html | 6 +- .../reference/global_objects/number/nan/index.html | 34 +-- .../global_objects/object/constructor/index.html | 2 +- .../global_objects/object/create/index.html | 8 +- .../object/defineproperties/index.html | 2 +- .../object/defineproperty/index.html | 2 +- .../global_objects/object/freeze/index.html | 2 +- .../object/getownpropertydescriptor/index.html | 6 +- .../object/getownpropertynames/index.html | 4 +- .../object/getprototypeof/index.html | 20 +- .../global_objects/object/isextensible/index.html | 6 +- .../global_objects/object/isfrozen/index.html | 2 +- .../global_objects/object/issealed/index.html | 4 +- .../global_objects/object/keys/index.html | 4 +- .../object/preventextensions/index.html | 2 +- .../global_objects/object/seal/index.html | 2 +- .../global_objects/object/valueof/index.html | 6 +- .../reference/global_objects/parseint/index.html | 6 +- .../global_objects/promise/catch/index.html | 22 +- .../reference/global_objects/promise/index.html | 2 +- .../global_objects/regexp/exec/index.html | 2 +- .../reference/global_objects/regexp/index.html | 4 +- .../global_objects/regexp/lastindex/index.html | 57 ++-- .../reference/global_objects/set/clear/index.html | 2 +- .../global_objects/string/concat/index.html | 2 +- .../global_objects/string/fixed/index.html | 2 +- .../global_objects/string/length/index.html | 56 ++-- .../global_objects/string/replace/index.html | 4 +- .../global_objects/string/slice/index.html | 6 +- .../global_objects/string/substr/index.html | 2 +- .../global_objects/string/tolowercase/index.html | 12 +- .../reference/global_objects/symbol/index.html | 6 +- .../global_objects/weakmap/get/index.html | 2 +- .../reference/operators/comma_operator/index.html | 2 +- .../reference/operators/function/index.html | 2 +- .../javascript/reference/operators/in/index.html | 6 +- .../reference/operators/typeof/index.html | 4 +- .../reference/statements/debugger/index.html | 4 +- .../reference/statements/do...while/index.html | 2 +- .../reference/statements/for...in/index.html | 4 +- .../reference/statements/function/index.html | 14 +- .../reference/statements/function_star_/index.html | 2 +- .../javascript/reference/strict_mode/index.html | 8 +- .../reference/template_literals/index.html | 12 +- 105 files changed, 687 insertions(+), 747 deletions(-) (limited to 'files/zh-cn') diff --git a/files/zh-cn/web/javascript/closures/index.html b/files/zh-cn/web/javascript/closures/index.html index 3bf409fe66..a3412be7ca 100644 --- a/files/zh-cn/web/javascript/closures/index.html +++ b/files/zh-cn/web/javascript/closures/index.html @@ -18,16 +18,14 @@ translation_of: Web/JavaScript/Closures

请看下面的代码:

-
function init() {
-    var name = "Mozilla"; // name 是一个被 init 创建的局部变量
-    function displayName() { // displayName() 是内部函数,一个闭包
-        alert(name); // 使用了父函数中声明的变量
-    }
-    displayName();
+  var name = "Mozilla"; // name 是一个被 init 创建的局部变量
+  function displayName() { // displayName() 是内部函数,一个闭包
+      alert(name); // 使用了父函数中声明的变量
+  }
+  displayName();
 }
 init();
-

init() 创建了一个局部变量 name 和一个名为 displayName() 的函数。displayName() 是定义在 init() 里的内部函数,并且仅在 init() 函数体内可用。请注意,displayName() 没有自己的局部变量。然而,因为它可以访问到外部函数的变量,所以 displayName() 可以使用父函数 init() 中声明的变量 name

diff --git a/files/zh-cn/web/javascript/enumerability_and_ownership_of_properties/index.html b/files/zh-cn/web/javascript/enumerability_and_ownership_of_properties/index.html index e7401b7cc1..a20bd79eec 100644 --- a/files/zh-cn/web/javascript/enumerability_and_ownership_of_properties/index.html +++ b/files/zh-cn/web/javascript/enumerability_and_ownership_of_properties/index.html @@ -11,15 +11,15 @@ translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties

可枚举属性是指那些内部 “可枚举” 标志设置为 true 的属性,对于通过直接的赋值和属性初始化的属性,该标识值默认为即为 true,对于通过 Object.defineProperty 等定义的属性,该标识值默认为 false。可枚举的属性可以通过 for...in 循环进行遍历(除非该属性名是一个 Symbol)。属性的所有权是通过判断该属性是否直接属于某个对象决定的,而不是通过原型链继承的。一个对象的所有的属性可以一次性的获取到。有一些内置的方法可以用于判断、迭代/枚举以及获取对象的一个或一组属性,下表对这些方法进行了列举。对于部分不可用的类别,下方的示例代码对获取方法进行了演示。

-
+
- - - - + + + + @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties - + @@ -70,7 +70,7 @@ translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties - + @@ -96,7 +96,7 @@ translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties - + @@ -210,7 +210,7 @@ translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties

统计表

-
+
属性的可枚举性和所有权 - 内置的判断、访问和迭代方法
作用自身对象自身对象及其原型链仅原型链作用自身对象自身对象及其原型链仅原型链
判断
可枚举属性 不可枚举属性可枚举属性及不可枚举属性可枚举属性及不可枚举属性
可枚举属性 不可枚举属性可枚举属性及不可枚举属性可枚举属性及不可枚举属性
可枚举属性 不可枚举属性可枚举属性及不可枚举属性可枚举属性及不可枚举属性
diff --git a/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html b/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html index 5d8e0d7528..c9e1e5ae71 100644 --- a/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html +++ b/files/zh-cn/web/javascript/equality_comparisons_and_sameness/index.html @@ -67,74 +67,74 @@ console.log(obj === undefined); // false - + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + @@ -204,174 +204,174 @@ function attemptMutation(v) - - - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
被比较值 B被比较值 B
UndefinedNullNumberStringBooleanObjectUndefinedNullNumberStringBooleanObject
被比较值 A UndefinedtruetruefalsefalsefalseIsFalsy(B)truetruefalsefalsefalseIsFalsy(B)
NulltruetruefalsefalsefalseIsFalsy(B)truetruefalsefalsefalseIsFalsy(B)
NumberfalsefalseA === BA === ToNumber(B)A=== ToNumber(B) A== ToPrimitive(B)falsefalseA === BA === ToNumber(B)A=== ToNumber(B) A== ToPrimitive(B)
StringfalsefalseToNumber(A) === BA === BToNumber(A) === ToNumber(B)ToPrimitive(B) == AfalsefalseToNumber(A) === BA === BToNumber(A) === ToNumber(B)ToPrimitive(B) == A
BooleanfalsefalseToNumber(A) === BToNumber(A) === ToNumber(B)A === BToNumber(A) == ToPrimitive(B)falsefalseToNumber(A) === BToNumber(A) === ToNumber(B)A === BToNumber(A) == ToPrimitive(B)
ObjectfalsefalseToPrimitive(A) == BToPrimitive(A) == BToPrimitive(A) == ToNumber(B) + falsefalseToPrimitive(A) == BToPrimitive(A) == BToPrimitive(A) == ToNumber(B)

A === B

判等
xy=====Object.isxy=====Object.is
undefined undefinedtruetruetruetruetruetrue
null nulltruetruetruetruetruetrue
true truetruetruetruetruetruetrue
false falsetruetruetruetruetruetrue
"foo" "foo"truetruetruetruetruetrue
0 0truetruetruetruetruetrue
+0 -0truetruefalsetruetruefalse
0 falsetruefalsefalsetruefalsefalse
"" falsetruefalsefalsetruefalsefalse
"" 0truefalsefalsetruefalsefalse
"0" 0truefalsefalsetruefalsefalse
"17" 17truefalsefalsetruefalsefalse
[1,2] "1,2"truefalsefalsetruefalsefalse
new String("foo") "foo"truefalsefalsetruefalsefalse
null undefinedtruefalsefalsetruefalsefalse
null falsefalsefalsefalsefalsefalsefalse
undefined falsefalsefalsefalsefalsefalsefalse
{ foo: "bar" } { foo: "bar" }falsefalsefalsefalsefalsefalse
new String("foo") new String("foo")falsefalsefalsefalsefalsefalse
0 nullfalsefalsefalsefalsefalsefalse
0 NaNfalsefalsefalsefalsefalsefalse
"foo" NaNfalsefalsefalsefalsefalsefalse
NaN NaNfalsefalsetruefalsefalsetrue
@@ -390,8 +390,6 @@ function attemptMutation(v)
let stoppingForce = obj.mass * -obj.velocity
-
-

如果obj.velocity0 (或计算结果为0), 一个-0就在上处产生并被赋值为stoppingForce的值.

diff --git a/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html b/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html index c8cb0eb24b..aa26c47e83 100644 --- a/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html +++ b/files/zh-cn/web/javascript/guide/control_flow_and_error_handling/index.html @@ -31,11 +31,9 @@ translation_of: Web/JavaScript/Guide/Control_flow_and_error_handling

语句块通常用于流程控制,如ifforwhile等等。

-
while (x < 10) {
   x++;
 }
-

这里{ x++; }就是语句块。

diff --git a/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html b/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html index 6e8cfdc61d..ef6ace35f4 100644 --- a/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html +++ b/files/zh-cn/web/javascript/guide/details_of_the_object_model/index.html @@ -91,7 +91,7 @@ translation_of: Web/JavaScript/Guide/Details_of_the_Object_Model

-
+
  • Employee 具有 name 属性(默认值为空的字符串)和 dept 属性(默认值为 "general")。
  • Manager 是 Employee的子类。它添加了 reports 属性(默认值为空的数组,以 Employee 对象数组作为它的值)。
  • @@ -279,7 +279,7 @@ var jane = new Engineer;

    当 JavaScript 执行 new 操作符时,它会先创建一个普通对象,并将这个普通对象中的 [[prototype]] 指向 WorkerBee.prototype ,然后再把这个普通对象设置为执行 WorkerBee 构造函数时 this  的值。该普通对象的 [[Prototype]] 决定其用于检索属性的原型链。当构造函数执行完成后,所有的属性都被设置完毕,JavaScript 返回之前创建的对象,通过赋值语句将它的引用赋值给变量 mark

    -

    这个过程不会显式的将 mark所继承的原型链中的属性作为本地属性存放在 mark 对象中。当访问属性时,JavaScript 将首先检查对象自身中是否存在该属性,如果有,则返回该属性的值。如果不存在,JavaScript会检查原型链(使用内置的 [[Prototype]] )。如果原型链中的某个对象包含该属性,则返回这个属性的值。如果遍历整条原型链都没有找到该属性,JavaScript 则认为对象中不存在该属性,返回一个 undefined。这样,mark 对象中将具有如下的属性和对应的值:

    +

    这个过程不会显式的将 mark所继承的原型链中的属性作为本地属性存放在 mark 对象中。当访问属性时,JavaScript 将首先检查对象自身中是否存在该属性,如果有,则返回该属性的值。如果不存在,JavaScript会检查原型链(使用内置的 [[Prototype]] )。如果原型链中的某个对象包含该属性,则返回这个属性的值。如果遍历整条原型链都没有找到该属性,JavaScript 则认为对象中不存在该属性,返回一个 undefined。这样,mark 对象中将具有如下的属性和对应的值:

    mark.name = "";
     mark.dept = "general";
    diff --git a/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html b/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
    index 7cb835c92b..8f45880006 100644
    --- a/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
    +++ b/files/zh-cn/web/javascript/guide/expressions_and_operators/index.html
    @@ -230,7 +230,7 @@ var var2 = 4;

    除了标准的算术运算符(+, - ,* /),JavaScript还提供了下表中的算术运算符。

    - +
    @@ -438,7 +438,7 @@ After: 10100000000000000110000000000001

    移位运算符列表如下。

    -

    移位运算符

    +

    移位运算符

    表 3.3 算术运算符
    @@ -474,9 +474,9 @@ After: 10100000000000000110000000000001

    逻辑运算符常用于布尔(逻辑)值之间; 当操作数都是布尔值时,返回值也是布尔值。 不过实际上&&||返回的是一个特定的操作数的值,所以当它用于非布尔值的时候,返回值就可能是非布尔值。 逻辑运算符的描述如下。

    -

    逻辑运算符

    +

    逻辑运算符

    -
    +
    @@ -786,7 +786,7 @@ if (theDay instanceof Date) {

    下表列出了描述符的优先级,从最高到最低。

    -

    运算符优先级

    +

    运算符优先级

    运算符
    diff --git a/files/zh-cn/web/javascript/guide/functions/index.html b/files/zh-cn/web/javascript/guide/functions/index.html index ab6677c5d9..f80d65ce3b 100644 --- a/files/zh-cn/web/javascript/guide/functions/index.html +++ b/files/zh-cn/web/javascript/guide/functions/index.html @@ -370,7 +370,7 @@ A(1); // logs 6 (1 + 2 + 3) outside()(10); // returns 20 instead of 10 -

    命名冲突发生在return x上,inside的参数xoutside变量x发生了冲突。这里的作用链域是{insideoutside, 全局对象}。因此insidex具有最高优先权,返回了20(insidex)而不是10(outsidex)。

    +

    命名冲突发生在return x上,inside的参数xoutside变量x发生了冲突。这里的作用链域是{insideoutside, 全局对象}。因此insidex具有最高优先权,返回了20(insidex)而不是10(outsidex)。

    闭包

    diff --git a/files/zh-cn/web/javascript/guide/indexed_collections/index.html b/files/zh-cn/web/javascript/guide/indexed_collections/index.html index 67c1afe469..53e12083af 100644 --- a/files/zh-cn/web/javascript/guide/indexed_collections/index.html +++ b/files/zh-cn/web/javascript/guide/indexed_collections/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Guide/Indexed_collections ---
    {{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Regular_Expressions", "Web/JavaScript/Guide/Keyed_Collections")}}
    -

    这个章节主要介绍了以索引进行排序的数据集合。包括数组以及类似于数组的数据结构,如 {{jsxref("Array")}} {{jsxref("TypedArray")}} 

    +

    这个章节主要介绍了以索引进行排序的数据集合。包括数组以及类似于数组的数据结构,如 {{jsxref("Array")}} {{jsxref("TypedArray")}} 

    数组对象(Array object)

    diff --git a/files/zh-cn/web/javascript/guide/regular_expressions/index.html b/files/zh-cn/web/javascript/guide/regular_expressions/index.html index d4b03b82de..5534db8860 100644 --- a/files/zh-cn/web/javascript/guide/regular_expressions/index.html +++ b/files/zh-cn/web/javascript/guide/regular_expressions/index.html @@ -567,33 +567,33 @@ console.log(newstr); - - + + - + - + - + - + - + - + diff --git a/files/zh-cn/web/javascript/guide/working_with_objects/index.html b/files/zh-cn/web/javascript/guide/working_with_objects/index.html index 28f6dd54d5..dbdc3294a6 100644 --- a/files/zh-cn/web/javascript/guide/working_with_objects/index.html +++ b/files/zh-cn/web/javascript/guide/working_with_objects/index.html @@ -24,10 +24,8 @@ translation_of: Web/JavaScript/Guide/Working_with_Objects

    一个 javascript 对象有很多属性。一个对象的属性可以被解释成一个附加到对象上的变量。对象的属性和普通的 javascript 变量基本没什么区别,仅仅是属性属于某个对象。属性定义了对象的特征(译注:动态语言面向对象的鸭子类型)。你可以通过点符号来访问一个对象的属性。

    -
    objectName.propertyName
     
    -

    和其他 javascript 变量一样,对象的名字(可以是普通的变量)和属性的名字都是大小写敏感的。你可以在定义一个属性的时候就给它赋值。例如,我们创建一个myCar的对象然后给他三个属性,make,model,year。具体如下所示:

    @@ -70,16 +68,14 @@ console.log(myObj);

    你也可以通过存储在变量中的字符串来访问属性:

    -
    var propertyName = "make";
    -myCar[propertyName] = "Ford";
    -
    -propertyName = "model";
    -myCar[propertyName] = "Mustang";
    -
    -
    + myCar[propertyName] = "Ford"; + + propertyName = "model"; + myCar[propertyName] = "Mustang"; + -

    你可以在  for...in 语句中使用方括号标记以枚举一个对象的所有属性。为了展示它如何工作,下面的函数当你将对象及其名称作为参数传入时,显示对象的属性:

    +

    你可以在  for...in 语句中使用方括号标记以枚举一个对象的所有属性。为了展示它如何工作,下面的函数当你将对象及其名称作为参数传入时,显示对象的属性:

    function showProps(obj, objName) {
       var result = "";
    @@ -147,7 +143,7 @@ myCar.year = 1969
     
     
     
    -

    这里 obj 是新对象的名称,每一个 property_i 是一个标识符(可以是一个名称、数字或字符串字面量),并且每个 value_i 是一个其值将被赋予 property_i 的表达式。obj 与赋值是可选的;如果你不需要在其他地方引用对象,你就不需要将它赋给一个变量。(注意在接受一条语句的地方,你可能需要将对象字面量括在括号里,从而避免将字面量与块语句相混淆)

    +

    这里 obj 是新对象的名称,每一个 property_i 是一个标识符(可以是一个名称、数字或字符串字面量),并且每个 value_i 是一个其值将被赋予 property_i 的表达式。obj 与赋值是可选的;如果你不需要在其他地方引用对象,你就不需要将它赋给一个变量。(注意在接受一条语句的地方,你可能需要将对象字面量括在括号里,从而避免将字面量与块语句相混淆)

    如果一个对象是通过在顶级脚本的对象初始化器创建的,则 JavaScript 在每次遇到包含该对象字面量的表达式时都会创建对象。同样的,在函数中的初始化器在每次函数调用时也会被创建。

    @@ -285,7 +281,7 @@ fish.displayType(); // Output:Fishes car1.color = "black";
    -

    参见 JavaScript Reference 中 Function 对象的 prototype 属性 。

    +

    参见 JavaScript Reference 中 Function 对象的 prototype 属性 。

    定义方法

    @@ -306,7 +302,7 @@ var myObj = { }; -

    这里 objectName 是一个已经存在的对象,methodname 是方法的名称,而 function_name 是函数的名称。

    +

    这里 objectName 是一个已经存在的对象,methodname 是方法的名称,而 function_name 是函数的名称。

    你可以在对象的上下文中象这样调用方法:

    @@ -463,7 +459,7 @@ console.log(o.b) // Runs the getter, which yields a + 1 or 6

    删除属性

    -

    你可以用 delete 操作符删除一个不是继承而来的属性。下面的例子说明如何删除一个属性:

    +

    你可以用 delete 操作符删除一个不是继承而来的属性。下面的例子说明如何删除一个属性:

    //Creates a new object, myobj, with two properties, a and b.
     var myobj = new Object;
    diff --git a/files/zh-cn/web/javascript/inheritance_and_the_prototype_chain/index.html b/files/zh-cn/web/javascript/inheritance_and_the_prototype_chain/index.html
    index 57f9c2bf2a..31f0522871 100644
    --- a/files/zh-cn/web/javascript/inheritance_and_the_prototype_chain/index.html
    +++ b/files/zh-cn/web/javascript/inheritance_and_the_prototype_chain/index.html
    @@ -353,155 +353,153 @@ console.log(g.__proto__.hasOwnProperty('addVertex'));
     
     

    下面列举四种用于拓展原型链的方法,以及他们的优势和缺陷。下列四个例子都创建了完全相同的 inst 对象(所以在控制台上的输出也是一致的),为了举例,唯一的区别是他们的创建方法不同。

    -
    正则表达式标志
    标志描述标志描述
    gg 全局搜索。
    ii 不区分大小写搜索。
    mm 多行搜索。
    ss 允许 . 匹配换行符。
    uu 使用unicode码的模式进行匹配。
    yy 执行“粘性(sticky)”搜索,匹配从目标字符串的当前位置开始。
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    名称例子优势缺陷
    New-initialization -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto = new foo;
    -proto.bar_prop = "bar val";
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop);
    -
    支持目前以及所有可想象到的浏览器(IE5.5都可以使用)。 这种方法非常快,非常符合标准,并且充分利用JIT优化。为使用此方法,必须对相关函数初始化。 在初始化过程中,构造函数可以存储每个对象必须生成的唯一信息。但是,这种唯一信息只生成一次,可能会带来潜在的问题。此外,构造函数的初始化,可能会将不需要的方法放在对象上。然而,如果你只在自己的代码中使用,你也清楚(或有通过注释等写明)各段代码在做什么,这些在大体上都不是问题(事实上,通常是有益处的)。
    Object.create -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto = Object.create(
    -  foo.prototype
    -);
    -proto.bar_prop = "bar val";
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop);
    -
    - -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto = Object.create(
    -  foo.prototype,
    -  {
    -    bar_prop: {
    -      value: "bar val"
    -    }
    -  }
    -);
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop)
    -
    支持当前所有非微软版本或者 IE9 以上版本的浏览器。允许一次性地直接设置 __proto__ 属性,以便浏览器能更好地优化对象。同时允许通过 Object.create(null) 来创建一个没有原型的对象。不支持 IE8 以下的版本。然而,随着微软不再对系统中运行的旧版本浏览器提供支持,这将不是在大多数应用中的主要问题。 另外,这个慢对象初始化在使用第二个参数的时候有可能成为一个性能黑洞,因为每个对象的描述符属性都有自己的描述对象。当以对象的格式处理成百上千的对象描述的时候,可能会造成严重的性能问题。
    -

    Object.setPrototypeOf

    -
    -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto = {
    -  bar_prop: "bar val"
    -};
    -Object.setPrototypeOf(
    -  proto, foo.prototype
    -);
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop);
    -
    - -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto;
    -proto=Object.setPrototypeOf(
    -  { bar_prop: "bar val" },
    -  foo.prototype
    -);
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop)
    -
    支持所有现代浏览器和微软IE9+浏览器。允许动态操作对象的原型,甚至能强制给通过 Object.create(null) 创建出来的没有原型的对象添加一个原型。这个方式表现并不好,应该被弃用。如果你在生产环境中使用这个方法,那么快速运行 Javascript 就是不可能的,因为许多浏览器优化了原型,尝试在调用实例之前猜测方法在内存中的位置,但是动态设置原型干扰了所有的优化,甚至可能使浏览器为了运行成功,使用完全未经优化的代码进行重编译。 不支持 IE8 及以下的浏览器版本。
    __proto__ -
    -function foo(){}
    -foo.prototype = {
    -  foo_prop: "foo val"
    -};
    -function bar(){}
    -var proto = {
    -  bar_prop: "bar val",
    -  __proto__: foo.prototype
    -};
    -bar.prototype = proto;
    -var inst = new bar;
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop);
    -
    - -
    -var inst = {
    -  __proto__: {
    -    bar_prop: "bar val",
    -    __proto__: {
    -      foo_prop: "foo val",
    -      __proto__: Object.prototype
    -    }
    -  }
    -};
    -console.log(inst.foo_prop);
    -console.log(inst.bar_prop)
    -
    支持所有现代非微软版本以及 IE11 以上版本的浏览器。将 __proto__ 设置为非对象的值会静默失败,并不会抛出错误。应该完全将其抛弃因为这个行为完全不具备性能可言。 如果你在生产环境中使用这个方法,那么快速运行 Javascript 就是不可能的,因为许多浏览器优化了原型,尝试在调用实例之前猜测方法在内存中的位置,但是动态设置原型干扰了所有的优化,甚至可能使浏览器为了运行成功,使用完全未经优化的代码进行重编译。不支持 IE10 及以下的浏览器版本。
    -
+ + + 名称 + 例子 + 优势 + 缺陷 + + + New-initialization + +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto = new foo;
+ proto.bar_prop = "bar val";
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop);
+ + 支持目前以及所有可想象到的浏览器(IE5.5都可以使用)。 这种方法非常快,非常符合标准,并且充分利用JIT优化。 + 为使用此方法,必须对相关函数初始化。 在初始化过程中,构造函数可以存储每个对象必须生成的唯一信息。但是,这种唯一信息只生成一次,可能会带来潜在的问题。此外,构造函数的初始化,可能会将不需要的方法放在对象上。然而,如果你只在自己的代码中使用,你也清楚(或有通过注释等写明)各段代码在做什么,这些在大体上都不是问题(事实上,通常是有益处的)。 + + + Object.create + +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto = Object.create(
+   foo.prototype
+ );
+ proto.bar_prop = "bar val";
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop);
+ 
+ +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto = Object.create(
+   foo.prototype,
+   {
+     bar_prop: {
+       value: "bar val"
+     }
+   }
+ );
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop)
+ + 支持当前所有非微软版本或者 IE9 以上版本的浏览器。允许一次性地直接设置 __proto__ 属性,以便浏览器能更好地优化对象。同时允许通过 Object.create(null) 来创建一个没有原型的对象。 + 不支持 IE8 以下的版本。然而,随着微软不再对系统中运行的旧版本浏览器提供支持,这将不是在大多数应用中的主要问题。 另外,这个慢对象初始化在使用第二个参数的时候有可能成为一个性能黑洞,因为每个对象的描述符属性都有自己的描述对象。当以对象的格式处理成百上千的对象描述的时候,可能会造成严重的性能问题。 + + + +

Object.setPrototypeOf

+ + +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto = {
+   bar_prop: "bar val"
+ };
+ Object.setPrototypeOf(
+   proto, foo.prototype
+ );
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop);
+ 
+ +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto;
+ proto=Object.setPrototypeOf(
+   { bar_prop: "bar val" },
+   foo.prototype
+ );
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop)
+ + 支持所有现代浏览器和微软IE9+浏览器。允许动态操作对象的原型,甚至能强制给通过 Object.create(null) 创建出来的没有原型的对象添加一个原型。 + 这个方式表现并不好,应该被弃用。如果你在生产环境中使用这个方法,那么快速运行 Javascript 就是不可能的,因为许多浏览器优化了原型,尝试在调用实例之前猜测方法在内存中的位置,但是动态设置原型干扰了所有的优化,甚至可能使浏览器为了运行成功,使用完全未经优化的代码进行重编译。 不支持 IE8 及以下的浏览器版本。 + + + __proto__ + +
+ function foo(){}
+ foo.prototype = {
+   foo_prop: "foo val"
+ };
+ function bar(){}
+ var proto = {
+   bar_prop: "bar val",
+   __proto__: foo.prototype
+ };
+ bar.prototype = proto;
+ var inst = new bar;
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop);
+ 
+ +
+ var inst = {
+   __proto__: {
+     bar_prop: "bar val",
+     __proto__: {
+       foo_prop: "foo val",
+       __proto__: Object.prototype
+     }
+   }
+ };
+ console.log(inst.foo_prop);
+ console.log(inst.bar_prop)
+ + 支持所有现代非微软版本以及 IE11 以上版本的浏览器。将 __proto__ 设置为非对象的值会静默失败,并不会抛出错误。 + 应该完全将其抛弃因为这个行为完全不具备性能可言。 如果你在生产环境中使用这个方法,那么快速运行 Javascript 就是不可能的,因为许多浏览器优化了原型,尝试在调用实例之前猜测方法在内存中的位置,但是动态设置原型干扰了所有的优化,甚至可能使浏览器为了运行成功,使用完全未经优化的代码进行重编译。不支持 IE10 及以下的浏览器版本。 + + +

prototypeObject.getPrototypeOf

diff --git a/files/zh-cn/web/javascript/javascript_technologies_overview/index.html b/files/zh-cn/web/javascript/javascript_technologies_overview/index.html index 9dcb7b2e5a..8de2f8ec27 100644 --- a/files/zh-cn/web/javascript/javascript_technologies_overview/index.html +++ b/files/zh-cn/web/javascript/javascript_technologies_overview/index.html @@ -93,4 +93,4 @@ translation_of: Web/JavaScript/JavaScript_technologies_overview
相信每个 Web 开发人员都曾经有过“DOM就是一团糟”的体验,因为浏览器对 DOM 的支持千差万别。造成这种局面的主要原因是DOM 规范并未清晰定义很多重要的 DOM 特性。另外,一些浏览器也增加了不兼容的特性(例如 Intenet Explorer 的事件模型)。自 2011 年 6 月以来,W3C,特别是 WHATWG 都在对旧特性进行细节定义,以提高互通性。浏览器也在基于这些更加详细的规范改善它们的实现方式。
-

要实现跨浏览器的兼容性,一个常见的但可能不是最可靠的方式就是使用 JavaScript 库。这些库对于 DOM 特性进行抽象,以确保它们所提供的 API 在不同的浏览器上行为一致。被广泛采用的框架有 jQueryprototypeYUI

+

要实现跨浏览器的兼容性,一个常见的但可能不是最可靠的方式就是使用 JavaScript 库。这些库对于 DOM 特性进行抽象,以确保它们所提供的 API 在不同的浏览器上行为一致。被广泛采用的框架有 jQueryprototypeYUI

diff --git a/files/zh-cn/web/javascript/reference/classes/extends/index.html b/files/zh-cn/web/javascript/reference/classes/extends/index.html index c7dbb72d18..37223f83ee 100644 --- a/files/zh-cn/web/javascript/reference/classes/extends/index.html +++ b/files/zh-cn/web/javascript/reference/classes/extends/index.html @@ -25,7 +25,7 @@ translation_of: Web/JavaScript/Reference/Classes/extends

使用 extends

-

第一个例子是根据名为 Polygon 类创建一个名为Square的类。这个例子是从这个在线演示中提取出来的。

+

第一个例子是根据名为 Polygon 类创建一个名为Square的类。这个例子是从这个在线演示中提取出来的。

class Square extends Polygon {
   constructor(length) {
diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/callee/index.html b/files/zh-cn/web/javascript/reference/functions/arguments/callee/index.html
index d814e6ce1f..a2847f3683 100644
--- a/files/zh-cn/web/javascript/reference/functions/arguments/callee/index.html
+++ b/files/zh-cn/web/javascript/reference/functions/arguments/callee/index.html
@@ -88,7 +88,7 @@ sillyFunction();

递归函数必须能够引用它本身。很典型的,函数通过自己的名字调用自己。然而,匿名函数 (通过 函数表达式 或者 函数构造器 创建) 没有名称。因此如果没有可访问的变量指向该函数,唯一能引用它的方式就是通过 arguments.callee

-

下面的例子定义了一个函数,按流程,定义并返回了一个阶乘函数。该例并不是很实用,并且几乎都能够用 命名函数表达式 实现同样结果的例子, and there are nearly no cases where the same result cannot be achieved with .

+

下面的例子定义了一个函数,按流程,定义并返回了一个阶乘函数。该例并不是很实用,并且几乎都能够用 命名函数表达式 实现同样结果的例子, and there are nearly no cases where the same result cannot be achieved with .

function create() {
    return function(n) {
diff --git a/files/zh-cn/web/javascript/reference/functions/arguments/index.html b/files/zh-cn/web/javascript/reference/functions/arguments/index.html
index 501794e7f3..04d14b0b4f 100644
--- a/files/zh-cn/web/javascript/reference/functions/arguments/index.html
+++ b/files/zh-cn/web/javascript/reference/functions/arguments/index.html
@@ -149,7 +149,7 @@ myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");

这个例子定义了一个函数通过一个字符串来创建HTML列表。这个函数唯一正式声明了的参数是一个字符。当该参数为 "u" 时,创建一个无序列表 (项目列表);当该参数为 "o" 时,则创建一个有序列表 (编号列表)。该函数定义如下:

-
function list(type) {
+
function list(type) {
   var result = "<" + type + "l><li>";
   var args = Array.prototype.slice.call(arguments, 1);
   result += args.join("</li><li>");
@@ -160,7 +160,7 @@ myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");

你可以传递任意数量的参数到该函数,并将每个参数作为一个项添加到指定类型的列表中。例如:

-
var listHTML = list("u", "One", "Two", "Three");
+
var listHTML = list("u", "One", "Two", "Three");
 
 /* listHTML is:
 
diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html
index 05f19bfcb5..07c1c104b5 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/array/fill/index.html
@@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/fill
 
 

fill 方法故意被设计成通用方法, 该方法不要求 this 是数组对象。

-

fill 方法是个可变方法, 它会改变调用它的 this 对象本身, 然后返回它, 而并不是返回一个副本。

+

fill 方法是个可变方法, 它会改变调用它的 this 对象本身, 然后返回它, 而并不是返回一个副本。

当一个对象被传递给 fill方法的时候, 填充数组的是这个对象的引用。

diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html index b0c8967e8e..ecde3c0f25 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/findindex/index.html @@ -37,7 +37,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/findIndex
thisArg
-
可选。执行callback时作为this对象的值.
+
可选。执行callback时作为this对象的值.

返回值

diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html index 1517622c81..15e10d0329 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html @@ -334,7 +334,7 @@ if (!Array.prototype.map) {

{{Compat("javascript.builtins.Array.map")}}

-

相关链接

+

相关链接

  • {{jsxref("Array.prototype.forEach()")}}
  • diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html index 25e4a88a23..9013ce9446 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/of/index.html @@ -45,7 +45,7 @@ Array(1, 2, 3); // [1, 2, 3]

    示例

    -
    Array.of(1);         // [1]
    +
    Array.of(1);         // [1]
     Array.of(1, 2, 3);   // [1, 2, 3]
     Array.of(undefined); // [undefined]
     
    @@ -54,7 +54,7 @@ Array.of(undefined); // [undefined]

    如果原生不支持的话,在其他代码之前执行以下代码会创建 Array.of() 。

    -
    if (!Array.of) {
    +
    if (!Array.of) {
       Array.of = function() {
         return Array.prototype.slice.call(arguments);
       };
    diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/pop/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/pop/index.html
    index 51fc625019..3e6caa6795 100644
    --- a/files/zh-cn/web/javascript/reference/global_objects/array/pop/index.html
    +++ b/files/zh-cn/web/javascript/reference/global_objects/array/pop/index.html
    @@ -50,7 +50,7 @@ console.log(popped);
     // surgeon
     
    -

    规范

    +

    规范

    diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/push/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/push/index.html index 3be7c12520..032e985d22 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/push/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/push/index.html @@ -32,11 +32,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/push
    被添加到数组末尾的元素。
    -

    返回值

    +

    返回值

    当调用该方法时,新的 {{jsxref("Array.length", "length")}} 属性值将被返回。

    -

    描述

    +

    描述

    push方法将值追加到数组中。

    diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html index c362c85c77..11e8a7ac85 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reduce/index.html @@ -157,13 +157,6 @@ var maxCallback2 = ( max, cur ) => Math.max( max, cur );
    - - - - - -
    -

    reduce返回的值将是最后一次回调返回值(10)。

    你还可以使用{{jsxref("Functions/Arrow_functions", "箭头函数","",1)}}来代替完整的函数。 下面的代码将产生与上面的代码相同的输出:

    diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html index 1245486db3..793a4fd3a3 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reduceright/index.html @@ -118,7 +118,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight

    一共会调用四次回调函数,每次调用的参数及返回值如下:

    - +
    @@ -174,7 +174,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/ReduceRight }, 10); -
    callback
    +
    diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/reverse/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/reverse/index.html index a9c984245f..b408aa046f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/reverse/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/reverse/index.html @@ -20,23 +20,23 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/reverse
    -

    语法

    +

    语法

     arr.reverse()
    -

    返回值

    +

    返回值

    颠倒后的数组。

    -

    描述

    +

    描述

    reverse 方法颠倒数组中元素的位置,改变了数组,并返回该数组的引用。

    reverse方法是特意类化的;此方法可被 called 或 applied于类似数组对象。对象如果不包含反映一系列连续的、基于零的数值属性中的最后一个长度的属性,则该对象可能不会以任何有意义的方式运行。

    -

    示例

    +

    示例

    -

    颠倒数组中的元素

    +

    颠倒数组中的元素

    下例将会创建一个数组 sourceArray,其包含三个元素,然后颠倒该数组。

    @@ -95,7 +95,7 @@ console.log(a); // {0: 3, 1: 2, 2: 1, length: 3}
    callback
    -

    规范

    +

    规范

    @@ -122,7 +122,7 @@ console.log(a); // {0: 3, 1: 2, 2: 1, length: 3}
    -

    浏览器兼容性

    +

    浏览器兼容性

    @@ -132,7 +132,7 @@ console.log(a); // {0: 3, 1: 2, 2: 1, length: 3}
-

相关链接

+

相关链接

  • {{jsxref("Array.prototype.join()")}}
  • diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/slice/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/slice/index.html index 0aa5dc1186..d62b834d40 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/slice/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/slice/index.html @@ -201,7 +201,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3] }()); -

    规范

    +

    规范

    @@ -234,7 +234,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3]
    -

    浏览器兼容性

    +

    浏览器兼容性

    @@ -242,7 +242,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3]

    {{Compat("javascript.builtins.Array.slice")}}

    -

    相关链接

    +

    相关链接

    • {{jsxref("Array.prototype.splice()")}}
    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html index c6e408edd2..8c5aabec0f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/some/index.html @@ -50,7 +50,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/some

      some() 为数组中的每一个元素执行一次 callback 函数,直到找到一个使得 callback 返回一个“真值”(即可转换为布尔值 true 的值)。如果找到了这样一个值,some() 将会立即返回 true。否则,some() 返回 falsecallback 只会在那些”有值“的索引上被调用,不会在那些被删除或从来未被赋值的索引上调用。

      -

      callback 被调用时传入三个参数:元素的值,元素的索引,被遍历的数组。

      +

      callback 被调用时传入三个参数:元素的值,元素的索引,被遍历的数组。

      如果一个thisArg参数提供给some(),它将被用作调用的 callback的 this 值。否则, 它的 this value将是 undefinedthis的值最终通过callback来观察,根据 the usual rules for determining the this seen by a function的this判定规则来确定。

      diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html index 7b92b97033..566ba9e61e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint64array/index.html @@ -57,7 +57,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/BigInt64Array
      -
      用静态值填充从起始索引到结束索引的数组的所有元素。另请参见{jsxref(“Array.prototype.fill()")}}
      +
      用静态值填充从起始索引到结束索引的数组的所有元素。另请参见{jsxref(“Array.prototype.fill()")}}
      diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html index 4bbfc8ad23..5f7d438415 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getdate/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDate

      语法

      -
      dateObj.getDate()
      +
      dateObj.getDate()

      参数

      @@ -27,14 +27,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDate

      例子: 使用getDate()方法

      -

      下面第二条语句将值25赋给 day 变量,该值基于日期对象 Xmax95的值。

      +

      下面第二条语句将值25赋给 day 变量,该值基于日期对象 Xmax95的值。

      -
      var Xmas95 = new Date("December 25, 1995 23:15:00");
      +
      var Xmas95 = new Date("December 25, 1995 23:15:00");
       var day = Xmas95.getDate();
       
       alert(day); // 25
      -

      规范

      +

      规范

      @@ -63,11 +63,11 @@ alert(day); // 25
      -

      浏览器兼容性

      +

      浏览器兼容性

      {{Compat("javascript.builtins.Date.getDate")}}

      -

      相关链接

      +

      相关链接

      • {{jsxref("Date.prototype.getUTCDate()")}}
      • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html index e9b18b852e..b2ee4a80cd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getday/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay

        语法

        -
        dateObj.getDay()
        +
        dateObj.getDay()
         

        返回值

        @@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay

        下面第二条语句,基于{{jsxref("Date")}}对象 Xmas95 的值,把 1 赋值给 weekday。也就是说1995年12月25日是星期一。

        -
        var Xmas95 = new Date("December 25, 1995 23:15:30");
        +
        var Xmas95 = new Date("December 25, 1995 23:15:30");
         var weekday = Xmas95.getDay();
         
         console.log(weekday); // 1
        @@ -41,7 +41,7 @@ console.log(new Intl.DateTimeFormat('de-DE', options).format(Xmas95)); // Montag
        -

        规范

        +

        规范

        @@ -73,11 +73,11 @@ console.log(new Intl.DateTimeFormat('de-DE', options).format(Xmas95));
        -

        浏览器兼容性

        +

        浏览器兼容性

        {{Compat("javascript.builtins.Date.getDay")}}

        -

        相关链接

        +

        相关链接

        • {{jsxref("Date.prototype.getUTCDate()")}}
        • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html index 7c4cf29b9a..6b8638c52d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear

          语法

          -
          dateObj.getFullYear()
          +
          dateObj.getFullYear()
           

          返回值

          @@ -42,7 +42,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear var year = today.getFullYear();
          -

          规范

          +

          规范

          @@ -74,11 +74,11 @@ var year = today.getFullYear();
          -

          浏览器兼容性

          +

          浏览器兼容性

          {{Compat("javascript.builtins.Date.getFullYear")}}

          -

          相关链接

          +

          相关链接

          • {{jsxref("Date.prototype.getUTCFullYear()")}}
          • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html index eb8ad854e1..fda9396354 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours

            语法

            -
            dateObj.getHours()
            +
            dateObj.getHours()

            参数

            @@ -29,12 +29,12 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours

            下面第二条语句,基于日期对象 Xmas95 的值,把 23 赋值给了变量 hours。

            -
            var Xmas95 = new Date("December 25, 1995 23:15:00");
            +
            var Xmas95 = new Date("December 25, 1995 23:15:00");
             var hours = Xmas95.getHours();
             
             alert(hours); // 23
            -

            规范

            +

            规范

            @@ -61,11 +61,11 @@ alert(hours); // 23
            -

            浏览器兼容性

            +

            浏览器兼容性

            {{Compat("javascript.builtins.Date.getHours")}}

            -

            相关链接

            +

            相关链接

            • {{jsxref("Date.prototype.getUTCHours()")}}
            • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html index be3ebe8f9b..c5dd09e3d9 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmilliseconds/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds

              语法

              -
              dateObj.getMilliseconds()
              +
              dateObj.getMilliseconds()

              参数

              @@ -29,11 +29,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds

              下例中,将当前时间的毫秒数赋值给变量 ms

              -
              var ms;
              +
              var ms;
               Today = new Date();
               ms = Today.getMilliseconds();
              -

              规范

              +

              规范

              @@ -60,11 +60,11 @@ ms = Today.getMilliseconds();
              -

              浏览器兼容性

              +

              浏览器兼容性

              {{Compat("javascript.builtins.Date.getMilliseconds")}}

              -

              相关链接

              +

              相关链接

              • {{jsxref("Date.prototype.getUTCMilliseconds()")}}
              • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html index 7a1fd0f433..8322a9e813 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getminutes/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMinutes

                语法

                -
                dateObj.getMinutes()
                +
                dateObj.getMinutes()

                参数

                @@ -27,10 +27,10 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMinutes

                下例中,第二行语句运行过后,变量 minutes 的值为15,也就是说 Xmas95 这个日期对象的值为某时15分某秒。

                -
                var Xmas95 = new Date("December 25, 1995 23:15:00");
                +
                var Xmas95 = new Date("December 25, 1995 23:15:00");
                 var minutes = Xmas95.getMinutes();
                -

                规范

                +

                规范

                @@ -57,13 +57,13 @@ var minutes = Xmas95.getMinutes();
                -

                浏览器兼容性

                +

                浏览器兼容性

                 

                {{Compat("javascript.builtins.Date.getMinutes")}}

                -

                相关链接

                +

                相关链接

                • {{jsxref("Date.prototype.getUTCMinutes()")}}
                • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html index 0002ecf4a1..63a953f263 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html @@ -79,7 +79,7 @@ console.log(month); // 11

                {{Compat("javascript.builtins.Date.getMonth")}}

                -

                相关链接

                +

                相关链接

                • {{jsxref("Date.prototype.getUTCMonth()")}}
                • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html index 457f166047..ded6203208 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getseconds/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getSeconds

                  语法

                  -
                  dateObj.getSeconds()
                  +
                  dateObj.getSeconds()

                  参数

                  @@ -29,14 +29,14 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getSeconds

                  下面第二条语句,基于日期对象 Xmas95 的值,把 30 赋值给变量 secs

                  -
                  var Xmas95 = new Date("December 25, 1995 23:15:30");
                  +
                  var Xmas95 = new Date("December 25, 1995 23:15:30");
                   var secs = Xmas95.getSeconds();
                  -
                   
                  +
                   
                  -
                   
                  +
                   
                  -

                  规范

                  +

                  规范

                  @@ -63,11 +63,11 @@ var secs = Xmas95.getSeconds();
                  -

                  浏览器兼容性

                  +

                  浏览器兼容性

                  {{Compat("javascript.builtins.Date.getSeconds")}}

                  -

                  相关链接

                  +

                  相关链接

                  • {{jsxref("Date.prototype.getUTCSeconds()")}}
                  • diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html index 87b619c759..7ee056a7df 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

                    语法

                    -
                    dateObj.getTimezoneOffset()
                    +
                    dateObj.getTimezoneOffset()

                    参数

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/index.html index 2c8e41406b..764d868453 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/index.html @@ -45,7 +45,7 @@ new Date(year, monthIndex [, day [, hours<

                    时间戳字符串

                    dateString
                    -
                    表示日期的字符串值。该字符串应该能被 {{jsxref("Date.parse()")}} 正确方法识别(即符合 IETF-compliant RFC 2822 timestamps 或 version of ISO8601)。 +
                    表示日期的字符串值。该字符串应该能被 {{jsxref("Date.parse()")}} 正确方法识别(即符合 IETF-compliant RFC 2822 timestamps 或 version of ISO8601)。

                    注意: 由于浏览器之间的差异与不一致性,强烈不推荐使用Date构造函数来解析日期字符串 (或使用与其等价的Date.parse)。对 RFC 2822 格式的日期仅有约定俗成的支持。 对 ISO 8601 格式的支持中,仅有日期的串 (例如 "1970-01-01") 会被处理为 UTC 而不是本地时间,与其他格式的串的处理不同。

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html index ad8ffc0c33..c8fcb530ab 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setfullyear/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear

                    语法

                    -
                    dateObj.setFullYear(yearValue[, monthValue[, dayValue]])
                    +
                    dateObj.setFullYear(yearValue[, monthValue[, dayValue]])

                    参数

                    @@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear

                    例子:使用setFullYear方法

                    -
                    var theBigDay = new Date();
                    +
                    var theBigDay = new Date();
                     theBigDay.setFullYear(1997);

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html index e351f33c33..a5b2885180 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/tolocalestring/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleString ---
                    {{JSRef("Global_Objects", "Date")}}
                    -

                    toLocaleString() 方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。

                    +

                    toLocaleString() 方法返回该日期对象的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。

                    {{EmbedInteractiveExample("pages/js/date-tolocalestring.html")}}
                    @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

                    参数

                    -

                    查看浏览器兼容性小节,看下哪些浏览器支持 locales 和 options 参数,还可以参看例子:检测 localesoptions 参数支持情况

                    +

                    查看浏览器兼容性小节,看下哪些浏览器支持 locales 和 options 参数,还可以参看例子:检测 localesoptions 参数支持情况

                    {{page('zh-CN/docs/JavaScript/Reference/Global_Objects/DateTimeFormat','Parameters')}}

                    @@ -42,7 +42,7 @@ date.toLocaleString();

                    例子:检测 locales 和 options 参数支持情况

                    -

                    locales 和 options 参数不是所有的浏览器都支持。为了检测一种实现环境(implementation)是否支持它们,可以使用不合法的语言标签,如果实现环境支持该参数,则会抛出一个 RangeError 异常,反之会忽略参数。

                    +

                    locales 和 options 参数不是所有的浏览器都支持。为了检测一种实现环境(implementation)是否支持它们,可以使用不合法的语言标签,如果实现环境支持该参数,则会抛出一个 RangeError 异常,反之会忽略参数。

                    function toLocaleStringSupportsLocales() {
                         try {
                    @@ -56,7 +56,7 @@ date.toLocaleString();
                     
                     

                    例子:使用 locales 参数

                    -

                    下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期和时间格式,必须确保使用 locales 参数指定了该语言(可能还需要设置某些回退语言)。

                    +

                    下例展示了本地化日期格式的一些变化。为了在应用的用户界面得到某种语言的日期和时间格式,必须确保使用 locales 参数指定了该语言(可能还需要设置某些回退语言)。

                    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
                     
                    @@ -90,7 +90,7 @@ alert(date.toLocaleString(["ban", "id"]));
                     
                     

                    例子:使用 options 参数

                    -

                    可以使用 options 参数来自定义 toLocaleString 方法返回的字符串。

                    +

                    可以使用 options 参数来自定义 toLocaleString 方法返回的字符串。

                    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
                     
                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html
                    index 2f31d53e2d..cf32bed733 100644
                    --- a/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html
                    +++ b/files/zh-cn/web/javascript/reference/global_objects/date/tolocaletimestring/index.html
                    @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString
                     ---
                     
                    {{JSRef("Global_Objects", "Date")}}
                    -

                    The toLocaleTimeString() 方法返回该日期对象时间部分的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。

                    +

                    The toLocaleTimeString() 方法返回该日期对象时间部分的字符串,该字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。

                    {{EmbedInteractiveExample("pages/js/date-tolocaletimestring.html")}}
                    @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString

                    参数

                    -

                    查看浏览器兼容性小节,看下哪些浏览器支持 locales 和 options 参数,还可以参看例子:检测 localesoptions 参数支持情况

                    +

                    查看浏览器兼容性小节,看下哪些浏览器支持 locales 和 options 参数,还可以参看例子:检测 localesoptions 参数支持情况

                    {{page('zh-US/docs/JavaScript/Reference/Global_Objects/DateTimeFormat','Parameters')}}

                    @@ -38,7 +38,7 @@ alert(date.toLocaleTimeString());

                    例子:检测 localesoptions 支持情况

                    -

                    locales 和 options 参数不是所有的浏览器都支持。为了检测一种实现环境(implementation)是否支持它们,可以使用不合法的语言标签,如果实现环境支持该参数,则会抛出一个 RangeError 异常,反之会忽略参数。

                    +

                    locales 和 options 参数不是所有的浏览器都支持。为了检测一种实现环境(implementation)是否支持它们,可以使用不合法的语言标签,如果实现环境支持该参数,则会抛出一个 RangeError 异常,反之会忽略参数。

                    function toLocaleTimeStringSupportsLocales() {
                         try {
                    @@ -52,7 +52,7 @@ alert(date.toLocaleTimeString());
                     
                     

                    例子:使用 locales 参数

                    -

                    下例展示了本地化时间格式的一些变化。为了在应用的用户界面得到某种语言的时间格式,必须确保使用 locales 参数指定了该语言(可能还需要设置某些回退语言)。

                    +

                    下例展示了本地化时间格式的一些变化。为了在应用的用户界面得到某种语言的时间格式,必须确保使用 locales 参数指定了该语言(可能还需要设置某些回退语言)。

                    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
                     
                    @@ -83,7 +83,7 @@ alert(date.toLocaleTimeString(["ban", "id"]));
                     
                     

                    例子:使用 options 参数

                    -

                    可以使用 options 参数来自定义 toLocaleTimeString 方法返回的字符串。

                    +

                    可以使用 options 参数来自定义 toLocaleTimeString 方法返回的字符串。

                    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
                     
                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.html
                    index b99486c6b6..faa183e9cf 100644
                    --- a/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.html
                    +++ b/files/zh-cn/web/javascript/reference/global_objects/date/totimestring/index.html
                    @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/toTimeString
                     
                     

                    {{jsxref("Global_Objects/Date", "Date")}} 对象的实例引用一个具体的时间点。 调用 {{jsxref("Date.toString", "toString")}} 方法以美式英语和人类易读的形式,返回日期对象的格式化字符串。在 SpiderMonkey 里,该字符串由日期部分(年月日)和其后的时间部分(时分秒和时区)组成。有时会需要获取时间部分的字符串,这可以由 toTimeString 方法完成。

                    -

                    The toTimeString method is especially useful because compliant engines implementing ECMA-262 may differ in the string obtained from toString for Date objects, as the format is implementation-dependent; simple string slicing approaches may not produce consistent results across multiple engines.

                    +

                    The toTimeString method is especially useful because compliant engines implementing ECMA-262 may differ in the string obtained from toString for Date objects, as the format is implementation-dependent; simple string slicing approaches may not produce consistent results across multiple engines.

                    例子

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/index.html index b9334c7969..fe9ad2deed 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/index.html @@ -49,37 +49,37 @@ const y = new Error('I was constructed via the "new" keyword!');

                    Error 类型

                    -

                    除了通用的Error构造函数外,JavaScript还有6个其他类型的错误构造函数。更多客户端异常,详见 Exception Handling Statements

                    +

                    除了通用的Error构造函数外,JavaScript还有6个其他类型的错误构造函数。更多客户端异常,详见 Exception Handling Statements

                    -
                    {{jsxref("EvalError")}}
                    +
                    {{jsxref("EvalError")}}
                    创建一个error实例,表示错误的原因:与 {{jsxref("Global_Objects/eval", "eval()")}} 有关。
                    -
                    {{jsxref("InternalError")}} {{non-standard_inline}}
                    +
                    {{jsxref("InternalError")}} {{non-standard_inline}}
                    创建一个代表Javascript引擎内部错误的异常抛出的实例。 如: "递归太多".
                    -
                    {{jsxref("RangeError", "RangeError")}}
                    +
                    {{jsxref("RangeError", "RangeError")}}
                    创建一个error实例,表示错误的原因:数值变量或参数超出其有效范围。
                    -
                    {{jsxref("ReferenceError")}}
                    +
                    {{jsxref("ReferenceError")}}
                    创建一个error实例,表示错误的原因:无效引用。
                    -
                    {{jsxref("SyntaxError")}}
                    +
                    {{jsxref("SyntaxError")}}
                    创建一个error实例,表示错误的原因:{{jsxref("Global_Objects/eval", "eval()")}}在解析代码的过程中发生的语法错误。
                    -
                    {{jsxref("TypeError")}}
                    +
                    {{jsxref("TypeError")}}
                    创建一个error实例,表示错误的原因:变量或参数不属于有效类型。
                    -
                    {{jsxref("URIError")}}
                    +
                    {{jsxref("URIError")}}
                    创建一个error实例,表示错误的原因:给 {{jsxref("Global_Objects/encodeURI", "encodeURI()")}}或  {{jsxref("Global_Objects/decodeURI", "decodeURI()")}}传递的参数无效。
                    @@ -141,7 +141,7 @@ const y = new Error('I was constructed via the "new" keyword!');

                    你可能希望自定义基于Error的异常类型,使得你能够 throw new MyError() 并可以使用 instanceof MyError 来检查某个异常的类型. 这种需求的通用解决方法如下.

                    -
                    +

                    注意,在FireFox中抛出自定义类型的异常会显示不正确的行号和文件名。

                    @@ -170,49 +170,49 @@ try { console.log(e.message); // 'custom message' }
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -
                    +
                    -

                    规范

                    +

                    规范

                    @@ -244,11 +244,11 @@ try {
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{Compat("javascript.builtins.Error")}}
                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Error.prototype")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html index 4d24a6f972..0903c6e059 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/name/index.html @@ -7,7 +7,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error/name

                      概述

                      -

                      name 属性表示error类型的名称.初始值为"Error".

                      +

                      name 属性表示error类型的名称.初始值为"Error".

                      描述

                      @@ -23,9 +23,9 @@ e.name = "ParseError"; // 修改之后,e.toString()会成为下 throw e; // "ParseError: Malformed input"
                    -

                    规范

                    +

                    规范

                    - +
                    @@ -50,20 +50,20 @@ throw e; // "ParseError: Malformed input"
                    Specification
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    -
                    {{CompatibilityTable}}
                    +
                    {{CompatibilityTable}}
                    -
                    - +
                    +
                    - - - - - - + + + + + + @@ -77,17 +77,17 @@ throw e; // "ParseError: Malformed input"
                    FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                    Basic support
                    -
                    - +
                    +
                    - - - - - - - + + + + + + + @@ -102,9 +102,9 @@ throw e; // "ParseError: Malformed input"
                    FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                    Basic support
                    -

                    相关链接

                    +

                    相关链接

                    -
                      +
                      • {{jsxref("Error.prototype.message")}}
                      • {{jsxref("Error.prototype.toString()")}}
                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/stack/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/stack/index.html index 0406826e77..53daa6aba0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/stack/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/stack/index.html @@ -100,7 +100,7 @@ try { // @file:///C:/example.html:7:6
                    -

                    你也可以使用//# sourceURL 命名eval源的指令。 也可以查看在 Debugger文档中的Debug eval 源blog post博客 。

                    +

                    你也可以使用//# sourceURL 命名eval源的指令。 也可以查看在 Debugger文档中的Debug eval 源blog post博客 。

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html index 944791e29c..89706614c4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/apply/index.html @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply

                    在调用一个存在的函数时,你可以为其指定一个 this 对象。 this 指当前对象,也就是正在调用这个函数的对象。 使用 apply, 你可以只写一次这个方法然后在另一个对象中继承它,而不用在新对象中重复写该方法。

                    -

                    apply 与 {{jsxref("Function.call", "call()")}} 非常相似,不同之处在于提供参数的方式。apply 使用参数数组而不是一组参数列表。apply 可以使用数组字面量(array literal),如 fun.apply(this, ['eat', 'bananas']),或数组对象, 如  fun.apply(this, new Array('eat', 'bananas'))

                    +

                    apply 与 {{jsxref("Function.call", "call()")}} 非常相似,不同之处在于提供参数的方式。apply 使用参数数组而不是一组参数列表。apply 可以使用数组字面量(array literal),如 fun.apply(this, ['eat', 'bananas']),或数组对象, 如  fun.apply(this, new Array('eat', 'bananas'))

                    你也可以使用 {{jsxref("Functions/arguments", "arguments")}}对象作为 argsArray 参数。 arguments 是一个函数的局部变量。 它可以被用作被调用对象的所有未指定的参数。 这样,你在使用apply函数的时候就不需要知道被调用对象的所有参数。 你可以使用arguments来把所有的参数传递给被调用对象。 被调用对象接下来就负责处理这些参数。

                    @@ -131,7 +131,7 @@ var min = minOfArray([5, 6, 2, 3, 7]);

                    使用闭包:

                    -
                    Function.prototype.construct = function(aArgs) {
                    +
                    Function.prototype.construct = function(aArgs) {
                       var fConstructor = this, fNewConstr = function() {
                         fConstructor.apply(this, aArgs);
                       };
                    @@ -139,7 +139,7 @@ var min = minOfArray([5, 6, 2, 3, 7]);
                       return new fNewConstr();
                     };
                    -

                    使用 Function 构造器:

                    +

                    使用 Function 构造器:

                    Function.prototype.construct = function (aArgs) {
                       var fNewConstr = new Function("");
                    @@ -168,7 +168,7 @@ console.log(myInstance.constructor);              // logs "MyConstructor"
                     
                     
                    注意: 这个非native的Function.construct方法无法和一些native构造器(例如Date)一起使用。 在这种情况下你必须使用Function.bind方法(例如,想象有如下一个数组要用在Date构造器中: [2012, 11, 4];这时你需要这样写: new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))() – -无论如何这不是最好的实现方式并且也许不该用在任何生产环境中).
                    -

                    规范

                    +

                    规范

                    @@ -200,11 +200,11 @@ console.log(myInstance.constructor);              // logs "MyConstructor"
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{Compat("javascript.builtins.Function.apply")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Functions_and_function_scope/arguments", "arguments ")}} object
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/bind/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/bind/index.html index 8940da5ad4..45ee18de46 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/bind/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/bind/index.html @@ -212,7 +212,7 @@ var slice = Function.prototype.apply.bind(unboundSlice); slice(arguments);
                    -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/call/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/call/index.html index 5b9fc87b48..5962c181a0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/call/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/call/index.html @@ -101,7 +101,7 @@ var obj = { greet.call(obj); // cats typically sleep between 12 and 16 hours -

                    使用 call 方法调用函数并且不指定第一个参数(argument

                    +

                    使用 call 方法调用函数并且不指定第一个参数(argument

                    在下面的例子中,我们调用了 display 方法,但并没有传递它的第一个参数。如果没有传递第一个参数,this 的值将会被绑定为全局对象。

                    @@ -127,7 +127,7 @@ function display() { display.call(); // Cannot read the property of 'sData' of undefined -

                    规范

                    +

                    规范

                    @@ -165,7 +165,7 @@ display.call(); // Cannot read the property of 'sData' of undefined

                    {{Compat("javascript.builtins.Function.call")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Function.prototype.bind()")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/name/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/name/index.html index 61f96599b8..0f7695c49e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/function/name/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/function/name/index.html @@ -46,7 +46,7 @@ var object = { console.log(f.name); // "f" console.log(object.someMethod.name); // "someMethod" -

                      你可以在 {{jsxref("Operators/Function", "函数表达式", "", 1)}}中定义函数的名称:

                      +

                      你可以在 {{jsxref("Operators/Function", "函数表达式", "", 1)}}中定义函数的名称:

                      var object = {
                         someMethod: function object_someMethod() {}
                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/function/tostring/index.html b/files/zh-cn/web/javascript/reference/global_objects/function/tostring/index.html
                      index 01bf4d2ce7..1ab33a0d1f 100644
                      --- a/files/zh-cn/web/javascript/reference/global_objects/function/tostring/index.html
                      +++ b/files/zh-cn/web/javascript/reference/global_objects/function/tostring/index.html
                      @@ -176,7 +176,7 @@ Function("a", "b")
                    -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/generator/index.html b/files/zh-cn/web/javascript/reference/global_objects/generator/index.html index f7e4fc037b..9efc414db4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/generator/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/generator/index.html @@ -59,7 +59,7 @@ console.log(gen.next().value);

                    传统的生成器对象

                    -

                    Firefox (SpiderMonkey) 在 JavaScript 1.7 中也实现了一个较早版本的生成器,其中函数声明中的星号(*)不是必需的 (只需在函数体中使用yield 关键字)。但是,旧式生成器已弃用。不要使用它们;他们将被删除  ({{bug(1083482)}})。

                    +

                    Firefox (SpiderMonkey) 在 JavaScript 1.7 中也实现了一个较早版本的生成器,其中函数声明中的星号(*)不是必需的 (只需在函数体中使用yield 关键字)。但是,旧式生成器已弃用。不要使用它们;他们将被删除  ({{bug(1083482)}})。

                    传统的生成器方法

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html index 296dcf5bc0..e69904ba41 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/isfinite/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isFinite

                    语法

                    -
                    isFinite(testValue)
                    +
                    isFinite(testValue)

                    参数

                    @@ -31,9 +31,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/isFinite

                    你可以用这个方法来判定一个数字是否是有限数字。isFinite 方法检测它参数的数值。如果参数是 NaN,正无穷大或者负无穷大,会返回false,其他返回 true

                    -

                    示例

                    +

                    示例

                    -
                    isFinite(Infinity);  // false
                    +
                    isFinite(Infinity);  // false
                     isFinite(NaN);       // false
                     isFinite(-Infinity); // false
                     
                    @@ -43,25 +43,25 @@ isFinite(2e64);      // true, 在更强壮的Number.isFinite(null)中将会得
                     
                     isFinite("0");       // true, 在更强壮的Number.isFinite('0')中将会得到false
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -
                     
                    +
                     
                    -

                    规范

                    +

                    规范

                    @@ -93,11 +93,11 @@ isFinite("0"); // true, 在更强壮的Number.isFinite('0')中将会得到
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{Compat("javascript.builtins.isFinite")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Number.isFinite()")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/json/index.html b/files/zh-cn/web/javascript/reference/global_objects/json/index.html index 9eb0663504..cbacf78288 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/json/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/json/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/JSON

                      JavaScript Object Notation

                      -

                      JSON 是一种语法,用来序列化对象、数组、数值、字符串、布尔值和 {{jsxref("null")}} 。它基于 JavaScript 语法,但与之不同:JavaScript不是JSON,JSON也不是JavaScript。参考 JSON:并不是JavaScript 的子集

                      +

                      JSON 是一种语法,用来序列化对象、数组、数值、字符串、布尔值和 {{jsxref("null")}} 。它基于 JavaScript 语法,但与之不同:JavaScript不是JSON,JSON也不是JavaScript。参考 JSON:并不是JavaScript 的子集

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html index bd41c06b44..6112c6e45e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/clz32/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/clz32
                      一个数字.
                      -

                      描述

                      +

                      描述

                      "clz32" 是 CountLeadingZeroes32 的缩写.

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html index 3098a43b63..ff321fb664 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/expm1/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/expm1

                      描述

                      -

                      参数 x 会被自动类型转换成 number 类型.

                      +

                      参数 x 会被自动类型转换成 number 类型.

                      expm1 是 "exponent minus 1" 的缩写.

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/log/index.html index 827dea60af..5be95016a8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log/index.html @@ -26,7 +26,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/log

                      如果指定的 number 为负数,则返回值为 NaN

                      -

                      由于 log 是 Math 的静态方法,所以应该像这样使用:Math.log(),而不是作为你创建的 Math 对象的方法。

                      +

                      由于 log 是 Math 的静态方法,所以应该像这样使用:Math.log(),而不是作为你创建的 Math 对象的方法。

                      示例

                      @@ -49,7 +49,7 @@ Math.log(10); // 2.302585092994046

                      如果你运行 getBaseLog(10, 1000),则会返回2.9999999999999996,非常接近实际答案:3,原因是浮点数精度问题。

                      -

                      规范

                      +

                      规范

                      JavaScript 与 JSON 的区别
                      @@ -76,7 +76,7 @@ Math.log(10); // 2.302585092994046
                      -

                      浏览器兼容性

                      +

                      浏览器兼容性

                      {{ CompatibilityTable() }}

                      @@ -84,12 +84,12 @@ Math.log(10); // 2.302585092994046
                    - - - - - - + + + + + + @@ -107,13 +107,13 @@ Math.log(10); // 2.302585092994046
                    FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                    Basic support
                    - - - - - - - + + + + + + + @@ -128,7 +128,7 @@ Math.log(10); // 2.302585092994046
                    FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                    Basic support
                    -

                    相关链接

                    +

                    相关链接

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.html index 403d4039a2..e80f580580 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/log1p/index.html @@ -28,9 +28,9 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/log1p

                    函数 y = log(x+1) 的图形是这样的:

                    -

                     log(x+1)

                    +

                     log(x+1)

                    -

                    示例

                    +

                    示例

                    Math.log1p(Math.E-1)  // 1
                     Math.log1p(0)         // 0
                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html
                    index 9c844c1447..fcfc82fbd5 100644
                    --- a/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html
                    +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pi/index.html
                    @@ -23,7 +23,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/PI
                     
                     

                    下面的函数使用 Math.PI 计算给定半径的圆周长:

                    -
                    function calculateCircumference (radius) {
                    +
                    function calculateCircumference (radius) {
                       return 2 * Math.PI * radius;
                     }
                     
                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html
                    index 3ede0647ac..9138f6d635 100644
                    --- a/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html
                    +++ b/files/zh-cn/web/javascript/reference/global_objects/math/pow/index.html
                    @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/pow
                     ---
                     
                    {{JSRef}}
                    -

                    Math.pow() 函数返回基数(base)的指数(exponent)次幂,即 baseexponent

                    +

                    Math.pow() 函数返回基数(base)的指数(exponent)次幂,即 baseexponent

                    {{EmbedInteractiveExample("pages/js/math-pow.html")}}

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/round/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/round/index.html index 6b9b7956ba..409b9dbaa1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/round/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/round/index.html @@ -40,7 +40,7 @@ x = Math.round(-20.5); //-20 x = Math.round(-20.51); //-21
                    -

                    小数舍入

                    +

                    小数舍入

                    // 闭包
                     (function(){
                    @@ -126,7 +126,7 @@ Math.ceil10(-59, 1); // -50
                     round(1.005, 2);    //1.01
                     
                    -

                    规范

                    +

                    规范

                    @@ -153,7 +153,7 @@ round(1.005, 2); //1.01
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{CompatibilityTable}}
                    @@ -161,12 +161,12 @@ round(1.005, 2); //1.01 - - - - - - + + + + + + @@ -184,12 +184,12 @@ round(1.005, 2); //1.01
                    FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
                    Basic support
                    - - - - - - + + + + + + @@ -203,7 +203,7 @@ round(1.005, 2); //1.01
                    FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileFeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
                    Basic support
                    -

                    相关链接

                    +

                    相关链接

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.html index 5171a2f9df..8eb81b8572 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/sqrt2/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/SQRT2 } getRoot2(); // 1.4142135623730951
                    -

                    规范

                    +

                    规范

                    @@ -41,18 +41,18 @@ getRoot2(); // 1.4142135623730951
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{ CompatibilityTable() }}

                    - - - - - - + + + + + + @@ -69,13 +69,13 @@ getRoot2(); // 1.4142135623730951
                    FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                    Basic support
                    - - - - - - - + + + + + + + @@ -89,7 +89,7 @@ getRoot2(); // 1.4142135623730951
                    FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                    Basic support
                    -

                    相关链接

                    +

                    相关链接

                    • The {{jsxref("Global_Objects/Math", "Math")}} object it belongs to.
                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.html index f260b85c58..485a96e75d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/math/trunc/index.html @@ -105,7 +105,7 @@ Math.trunc() // NaN

                    {{Compat("javascript.builtins.Math.trunc")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Math.abs()")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/nan/index.html b/files/zh-cn/web/javascript/reference/global_objects/nan/index.html index c83a017f48..95eda30e2e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/nan/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/nan/index.html @@ -40,7 +40,7 @@ valueIsNaN(Number.NaN); // true
                    isNaN('hello world');        // true
                     Number.isNaN('hello world'); // false
                    -

                    规范

                    +

                    规范

                    @@ -55,11 +55,11 @@ Number.isNaN('hello world'); // false
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{Compat("javascript.builtins.NaN")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Number.NaN")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/number/nan/index.html b/files/zh-cn/web/javascript/reference/global_objects/number/nan/index.html index e75b557e76..e7df054c6f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/number/nan/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/number/nan/index.html @@ -5,7 +5,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN ---
                      {{JSRef("Global_Objects", "Number")}}
                      -

                      概述

                      +

                      概述

                      Number.NaN 表示“非数字”(Not-A-Number)。和 {{jsxref("Global_Objects/NaN", "NaN")}} 相同。

                      @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN

                      {{js_property_attributes(0,0,0)}}

                      -

                      规范

                      +

                      规范

                      @@ -45,7 +45,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN
                      -

                      浏览器兼容性

                      +

                      浏览器兼容性

                      {{ CompatibilityTable() }}

                      @@ -53,12 +53,12 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN - - - - - - + + + + + + @@ -76,13 +76,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN
                      FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                      Basic support
                      - - - - - - - + + + + + + + @@ -97,7 +97,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN
                      FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                      Basic support
                      -

                      相关链接

                      +

                      相关链接

                      • 全局对象 {{jsxref("Global_Objects/NaN", "NaN")}}
                      • diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/constructor/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/constructor/index.html index b56ef4c920..ac1375763a 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/constructor/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/constructor/index.html @@ -196,7 +196,7 @@ Child.prototype.getOffsetByInitialPosition = function getOffsetByInitialPosition

                        总结:手动设置或更新构造函数可能会导致不同且有时令人困惑的后果。为了防止它,只需在每个特定情况下定义构造函数的角色。在大多数情况下,不使用构造函数,并且不需要重新分配构造函数。

                        -

                        规范

                        +

                        规范

                        diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html index 255cd9ec0c..9bd6e7589c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html @@ -159,7 +159,7 @@ o2 = Object.create({}, { } }); -

                        Polyfill

                        +

                        Polyfill

                        这个 polyfill 涵盖了主要的应用场景,它创建一个已经选择了原型的新对象,但没有把第二个参数考虑在内。

                        @@ -182,7 +182,7 @@ o2 = Object.create({}, { }; } -

                        规范

                        +

                        规范

                        @@ -213,11 +213,11 @@ o2 = Object.create({}, {

                        {{Compat("javascript.builtins.Object.create")}}

                        -

                        相关链接

                        +

                        相关链接

                        • {{jsxref("Object.defineProperty")}}
                        • {{jsxref("Object.defineProperties")}}
                        • {{jsxref("Object.prototype.isPrototypeOf")}}
                        • -
                        • John Resig's post on getPrototypeOf
                        • +
                        • John Resig's post on getPrototypeOf
                        diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html index e4d9e9ef7a..9758d0af9b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html @@ -141,7 +141,7 @@ Object.defineProperties(obj, { return obj; } -

                        规范

                        +

                        规范

                        diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html index b37662d5ab..74b6088e27 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html @@ -172,7 +172,7 @@ Object.defineProperty(obj, "key", withValue("static"));

                        示例

                        -

                        如果你想了解如何使用 Object.defineProperty 方法和类二进制标记语法,可以看看这些额外示例

                        +

                        如果你想了解如何使用 Object.defineProperty 方法和类二进制标记语法,可以看看这些额外示例

                        创建属性

                        diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/freeze/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/freeze/index.html index 947a54007d..bd48ad319b 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/freeze/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/freeze/index.html @@ -161,7 +161,7 @@ TypeError: 1 is not an object // ES5 code

                        Object.seal()密封的对象可以改变它们现有的属性。使用Object.freeze() 冻结的对象中现有属性是不可变的。

                        -

                        规范

                        +

                        规范

                        diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html index 7738e33117..b8432c64bd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html @@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDes
                        目标对象内属性名称
                        -

                        返回值

                        +

                        返回值

                        如果指定的属性存在于对象上,则返回其属性描述符对象(property descriptor),否则返回 {{jsxref("undefined")}}。

                        @@ -103,7 +103,7 @@ Object.getOwnPropertyDescriptor('foo', 0); // writable: false // } -

                        规范

                        +

                        规范

                        @@ -139,7 +139,7 @@ Object.getOwnPropertyDescriptor('foo', 0);
                        -
                        相关链接 
                        +
                        相关链接 
                        • {{jsxref("Object.defineProperty()")}}
                        • diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertynames/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertynames/index.html index b4ad24a572..3f86e43049 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertynames/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertynames/index.html @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNam

                          在给定对象上找到的自身属性对应的字符串数组。

                          -

                          描述

                          +

                          描述

                          Object.getOwnPropertyNames() 返回一个数组,该数组对元素是 obj自身拥有的枚举或不可枚举属性名称字符串。 数组中枚举属性的顺序与通过 {{jsxref("Statements/for...in", "for...in")}} 循环(或 {{jsxref("Object.keys")}})迭代该对象属性时一致。数组中不可枚举属性的顺序未定义。

                          @@ -155,7 +155,7 @@ Object.getOwnPropertyNames('foo');

                          Firefox 28 {{geckoRelease("28")}}之前,Object.getOwnPropertyNames 不会获取到 {{jsxref("Error")}} 对象的属性。该 bug 在后面的版本修复了 ({{bug("724768")}})。

                          -

                          相关链接

                          +

                          相关链接

                          • Enumerability and ownership of properties
                          • diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getprototypeof/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getprototypeof/index.html index df45e04217..2d8e4928f8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/getprototypeof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/getprototypeof/index.html @@ -65,30 +65,16 @@ Object.prototype === Object.getPrototypeOf( obj ); // true Object.prototype === Object.getPrototypeOf( {} ); // true -
                             
                            - -
                             
                            - -
                             
                            -

                            Notes

                            -

                            在 ES5 中,如果参数不是一个对象类型,将抛出一个{{jsxref("TypeError")}}异常。在 ES2015 中,参数会被强制转换为一个 {{jsxref("Object")}}

                            +

                            在 ES5 中,如果参数不是一个对象类型,将抛出一个{{jsxref("TypeError")}}异常。在 ES2015 中,参数会被强制转换为一个 {{jsxref("Object")}}

                            Object.getPrototypeOf('foo');
                             // TypeError: "foo" is not an object (ES5 code)
                             Object.getPrototypeOf('foo');
                             // String.prototype                  (ES2015 code)
                            -
                             
                            - -
                             
                            - -
                             
                            - -
                             
                            - -

                            规范

                            +

                            规范

                        @@ -129,7 +115,7 @@ Object.getPrototypeOf('foo');
                      • {{jsxref("Object.prototype.isPrototypeOf")}}
                      • {{jsxref("Object.setPrototypeOf()")}}
                      • {{jsxref("Object.prototype.__proto__")}}
                      • -
                      • John Resig's post on getPrototypeOf
                      • +
                      • John Resig's post on getPrototypeOf
                      • {{jsxref("Reflect.getPrototypeOf()")}}
                      • {{jsxref("AsyncFunction")}}
                      • diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html index 249ce52673..817dd1296a 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/isextensible/index.html @@ -49,7 +49,7 @@ Object.isExtensible(frozen); // === false

                         

                        -

                        注意

                        +

                        注意

                        在 ES5 中,如果参数不是一个对象类型,将抛出一个 {{jsxref("TypeError")}} 异常。在 ES6 中, non-object 参数将被视为一个不可扩展的普通对象,因此会返回 false 。

                        @@ -60,7 +60,7 @@ Object.isExtensible(1); // false (ES6 code) -

                        规范

                        +

                        规范

                        @@ -133,7 +133,7 @@ Object.isExtensible(1);
                        -

                        相关链接

                        +

                        相关链接

                        • {{jsxref("Object.preventExtensions")}}
                        • diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/isfrozen/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/isfrozen/index.html index c923cc5530..9a730a6d2c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/isfrozen/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/isfrozen/index.html @@ -108,7 +108,7 @@ Object.isFrozen(1); // true (ES2015 code)
                    -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html index e6a895f345..2a70e41e8e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html @@ -68,7 +68,7 @@ Object.isFrozen(s2); // === false, 属性"p"可写 var s3 = Object.seal({ get p() { return 0; } }); Object.isFrozen(s3); // === true ,访问器属性不考虑可写不可写,只考虑是否可配置 -

                    注意

                    +

                    注意

                    在ES5中,如果这个方法的参数不是一个对象(一个原始类型),那么它会导致{{jsxref("TypeError")}}。在ES2015中,非对象参数将被视为是一个密封的普通对象,只返回true

                    @@ -78,7 +78,7 @@ Object.isFrozen(s3); // === true ,访问器属性不考虑可写不可写,只 Object.isSealed(1); // true (ES2015 code) -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/keys/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/keys/index.html index b477b88320..3a778356b0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/keys/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/keys/index.html @@ -28,7 +28,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/keys

                    一个表示给定对象的所有可枚举属性的字符串数组。

                    -

                    描述

                    +

                    描述

                    Object.keys 返回一个所有元素为字符串的数组,其元素来自于从给定的object上面可直接枚举的属性。这些属性的顺序与手动遍历该对象属性时的一致。

                    @@ -110,7 +110,7 @@ Object.keys("foo");

                    另一个简单的实现,参见Javascript - Object.keys Browser Compatibility

                    -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/preventextensions/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/preventextensions/index.html index 9658716cff..f412762462 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/preventextensions/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/preventextensions/index.html @@ -86,7 +86,7 @@ fixed.__proto__ = { oh: 'hai' }; Object.preventExtensions(1); // 1 (ES2015 code) -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/seal/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/seal/index.html index 6fd23f3d1d..69d14321ee 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/seal/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/seal/index.html @@ -105,7 +105,7 @@ Object.seal(1);

                    使用Object.freeze()冻结的对象中的现有属性值是不可变的。用Object.seal()密封的对象可以改变其现有属性值。

                    -

                    规范

                    +

                    规范

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html index c9f98bebc4..e2627097bd 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/valueof/index.html @@ -7,7 +7,7 @@ tags: - Object translation_of: Web/JavaScript/Reference/Global_Objects/Object/valueOf --- -
                    {{JSRef}}
                    +
                    {{JSRef}}

                    valueOf() 方法返回指定对象的原始值。

                    @@ -81,8 +81,6 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/valueOf
                    MyNumberType.prototype.valueOf = function() { return customPrimitiveValue; };
                    -
                     
                    -

                    有了这样的一个方法,下一次每当MyNumberType要被转换为原始类型值时,JavaScript 在此之前会自动调用自定义的valueOf方法。

                    valueOf方法一般都会被 JavaScript 自动调用,但你也可以像下面代码那样自己调用:

                    @@ -90,7 +88,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/valueOf
                    myNumberType.valueOf()
                    -

                    注意:字符串上下文中的对象通过 {{jsxref("Object.toString", "toString()")}}方法转换,这与使用valueOf转换为原始字符串的{{jsxref("String")}}对象不同。所有对象都能转换成一个“[object 类型]”这种格式的字符串。但是很多对象不能转换为数字,布尔或函数。

                    +

                    注意:字符串上下文中的对象通过 {{jsxref("Object.toString", "toString()")}}方法转换,这与使用valueOf转换为原始字符串的{{jsxref("String")}}对象不同。所有对象都能转换成一个“[object 类型]”这种格式的字符串。但是很多对象不能转换为数字,布尔或函数。

                    示例

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html index 4f2def476a..fad8f4e3cc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/parseint/index.html @@ -128,7 +128,7 @@ parseInt(0.00000000000434, 10); // 非常小的数值变成 4
                    parseInt("0e0",16);
                    -

                    没有指定 radix 参数时的八进制解析

                    +

                    没有指定 radix 参数时的八进制解析

                    尽管 ECMAScript 3 已经不赞成这种做法,且 ECMAScript 5 已经禁止了这种做法,但是仍然有很多实现环境仍然把以 0 开头的数值字符串(numeric string)解释为一个八进制数。下面的例子可能返回八进制的结果,也可能返回十进制的结果。总是指定一个基数(radix)可以避免这种不可靠的行为。

                    @@ -139,7 +139,7 @@ parseInt("08"); // 0, '8' 不是八进制数字. -

                    ECMAScript 5 移除了八进制解析

                    +

                    ECMAScript 5 移除了八进制解析

                    ECMAScript 5 规范不再允许parseInt函数的实现环境把以0字符开始的字符串作为八进制数值。ECMAScript 5 陈述如下:

                    @@ -149,7 +149,7 @@ parseInt("08");

                    直至2013年,很多实现环境并没有采取新的规范所规定的做法, 而且由于必须兼容旧版的浏览器,所以永远都要明确给出radix参数的值.

                    -

                    一个更严格的解析函数

                    +

                    一个更严格的解析函数

                    有时采用一个更严格的方法来解析整型值很有用。此时可以使用正则表达式:

                    diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/catch/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/catch/index.html index 3bd0a41fd4..addf056e90 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/catch/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/catch/index.html @@ -10,16 +10,16 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise/catch

                    catch() 方法返回一个Promise,并且处理拒绝的情况。它的行为与调用{{jsxref("Promise.then", "Promise.prototype.then(undefined, onRejected)")}} 相同。 (事实上, calling obj.catch(onRejected) 内部calls obj.then(undefined, onRejected)).

                    -

                    语法

                    +

                    语法

                    -
                    p.catch(onRejected);
                    +
                    p.catch(onRejected);
                     
                     p.catch(function(reason) {
                        // 拒绝
                     });
                     
                    -

                    参数

                    +

                    参数

                    onRejected
                    @@ -34,15 +34,15 @@ p.catch(function(reason) {
                    -

                    描述

                    +

                    描述

                    catch 方法可以用于您的promise组合中的错误处理。

                    Internally calls Promise.prototype.then on the object upon which is called, passing the parameters undefined and the onRejected handler received; then returns the value of that call (which is a {{jsxref("Promise")}}).

                    -

                    示例

                    +

                    示例

                    -

                    使用链式语句的 catch方法

                    +

                    使用链式语句的 catch方法

                    var p1 = new Promise(function(resolve, reject) {
                       resolve('Success');
                    @@ -71,7 +71,7 @@ p1.then(function(value) {
                       console.log('Not fired due to the catch');
                     });
                    -

                    捕获抛出的错误

                    +

                    捕获抛出的错误

                    // 抛出一个错误,大多数时候将调用catch方法
                     var p1 = new Promise(function(resolve, reject) {
                    @@ -103,7 +103,7 @@ p3.catch(function(e) {
                        console.log(e); // 不会执行
                     });
                    -

                    如果已决议

                    +

                    如果已决议

                    //创建一个新的 Promise ,且已决议
                     var p1 = Promise.resolve("calling next");
                    @@ -122,7 +122,7 @@ p2.then(function (value) {
                         console.log(reason);
                     });
                    -

                    规范

                    +

                    规范

                    @@ -144,11 +144,11 @@ p2.then(function (value) {
                    -

                    浏览器兼容性

                    +

                    浏览器兼容性

                    {{Compat("javascript/promise","Promise.prototype.catch")}}

                    -

                    相关链接

                    +

                    相关链接

                    • {{jsxref("Promise")}}
                    • diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/index.html index 5a5fd2d613..a658fd4338 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/promise/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/promise/index.html @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Promise

                      待定状态的 Promise 对象要么会通过一个值被兑现(fulfilled),要么会通过一个原因(错误)被拒绝(rejected)。当这些情况之一发生时,我们用 promise 的 then 方法排列起来的相关处理程序就会被调用。如果 promise 在一个相应的处理程序被绑定时就已经被兑现或被拒绝了,那么这个处理程序就会被调用,因此在完成异步操作和绑定处理方法之间不会存在竞争状态。

                      -

                      因为 {{jsxref("Promise.then", "Promise.prototype.then")}} 和  {{jsxref("Promise.catch", "Promise.prototype.catch")}} 方法返回的是 promise, 所以它们可以被链式调用。

                      +

                      因为 {{jsxref("Promise.then", "Promise.prototype.then")}} 和  {{jsxref("Promise.catch", "Promise.prototype.catch")}} 方法返回的是 promise, 所以它们可以被链式调用。

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html index b7e9edf7ec..8ee22ffa6c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec

                      exec() 方法在一个指定字符串中执行一个搜索匹配。返回一个结果数组或 {{jsxref("null")}}。

                      -

                      在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 /foo/g or /foo/y),JavaScript {{jsxref("RegExp")}} 对象是有状态的。他们会将上次成功匹配后的位置记录在 {{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,exec() 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。

                      +

                      在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 /foo/g or /foo/y),JavaScript {{jsxref("RegExp")}} 对象是有状态的。他们会将上次成功匹配后的位置记录在 {{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,exec() 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。

                      如果你只是为了判断是否匹配(true或 false),可以使用 {{jsxref("RegExp.test()")}} 方法,或者 {{jsxref("String.search()")}} 方法。

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html index a4ca838294..a0bcd500de 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp

                      以下三种表达式都会创建相同的正则表达式:

                      -
                      /ab+c/i; //字面量形式
                      +
                      /ab+c/i; //字面量形式
                       new RegExp('ab+c', 'i'); // 首个参数为字符串模式的构造函数
                       new RegExp(/ab+c/, 'i'); // 首个参数为常规字面量的构造函数
                      @@ -213,7 +213,7 @@ console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx"

                      使用浏览器内建的URL API而非正则表达式来解析URL是更好的做法

                      -

                      规范

                      +

                      规范

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html index f7e667288f..92dadc8159 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html @@ -10,41 +10,34 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex ---
                      {{JSRef("Global_Objects", "RegExp")}}
                      -

                      概述

                      +

                      概述

                      lastIndex 是正则表达式的一个可读可写的整型属性,用来指定下一次匹配的起始索引。

                      {{js_property_attributes(1,0,0)}}
                      -

                      语法

                      -
                      lastIndex = regExpObj.lastIndex;
                      -

                      描述

                      +

                      语法

                      +
                      lastIndex = regExpObj.lastIndex;
                      +

                      描述

                      只有正则表达式使用了表示全局检索的 "g" 标志时,该属性才会起作用。此时应用下面的规则:

                      • 如果 lastIndex 大于字符串的长度,则 regexp.test 和 regexp.exec 将会匹配失败,然后 lastIndex 被设置为 0。
                      • -
                      • 如果 lastIndex 等于字符串的长度,且该正则表达式匹配空字符串,则该正则表达式匹配从 lastIndex 开始的字符串。(then the regular expression matches input starting at lastIndex.)
                      • +
                      • 如果 lastIndex 等于字符串的长度,且该正则表达式匹配空字符串,则该正则表达式匹配从 lastIndex 开始的字符串。(then the regular expression matches input starting at lastIndex.)
                      • 如果 lastIndex 等于字符串的长度,且该正则表达式不匹配空字符串 ,则该正则表达式不匹配字符串,lastIndex 被设置为 0.。
                      • 否则,lastIndex 被设置为紧随最近一次成功匹配的下一个位置。
                      -

                      示例

                      +

                      示例

                      考虑下面的语句:

                      var re = /(hi)?/g;
                      -
                      -  
                      +

                      匹配空字符串

                      console.log(re.exec("hi"));
                       console.log(re.lastIndex);
                      -
                      -  
                      -
                      -  
                      +

                      返回 ["hi", "hi"] ,lastIndex 等于 2。

                      console.log(re.exec("hi"));
                       console.log(re.lastIndex);
                      -
                      -  
                      -
                      -  
                      +

                      返回 ["", undefined],即一个数组,其第 0 个元素为匹配的字符串。此种情况下为空字符串,是因为 lastIndex 为 2(且一直是 2),"hi" 长度为 2。

                      -

                      规范

                      +

                      规范

                      @@ -70,18 +63,18 @@ console.log(re.lastIndex);
                      -

                      浏览器兼容性

                      +

                      浏览器兼容性

                      {{ CompatibilityTable() }}

                      - - - - - - + + + + + + @@ -98,13 +91,13 @@ console.log(re.lastIndex);
                      FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                      Basic support
                      - - - - - - - + + + + + + + @@ -118,7 +111,7 @@ console.log(re.lastIndex);
                      FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                      Basic support
                      -

                      相关链接

                      +

                      相关链接

                      • {{jsxref("RegExp.prototype.ignoreCase")}}
                      • {{jsxref("RegExp.prototype.global")}}
                      • diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/clear/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/clear/index.html index 567dd3dc4c..de14cee47c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/set/clear/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/set/clear/index.html @@ -112,7 +112,7 @@ mySet.has("bar") // false -

                        相关链接

                        +

                        相关链接

                        • {{jsxref("Set")}}
                        • diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html index 7b53403ac2..1f2e37ceb4 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html @@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/concat

                          如果参数不是字符串类型,它们在连接之前将会被转换成字符串。

                          -

                          性能

                          +

                          性能

                          强烈建议使用赋值操作符+, +=)代替 concat 方法。

                          diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html index 28dd7c8696..6fd1d90c0d 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/fixed/index.html @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/fixed

                          描述

                          -

                          fixed() 方法将一个字符串包裹在<tt></tt>标签中,比如: "<tt>str</tt>".

                          +

                          fixed() 方法将一个字符串包裹在<tt></tt>标签中,比如: "<tt>str</tt>".

                          举例

                          diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/length/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/length/index.html index 9ec301ff64..bf49c313f0 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/length/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/length/index.html @@ -10,11 +10,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/length ---

                          {{JSRef("Global_Objects", "String")}}

                          -

                          概述

                          +

                          概述

                          length 属性表示一个字符串的长度。

                          -

                          描述

                          +

                          描述

                          该属性返回字符串中字符编码单元的数量。JavaScript 使用 {{ interwiki("wikipedia", "UTF-16") }} 编码,该编码使用一个 16 比特的编码单元来表示大部分常见的字符,使用两个代码单元表示不常用的字符。因此 length 返回值可能与字符串中实际的字符数量不相同。

                          @@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/length

                          静态属性 String.length 返回 1。

                          -

                          示例

                          +

                          示例

                          var x = "Mozilla";
                           var empty = "";
                          @@ -33,23 +33,7 @@ console.log("Mozilla is " + x.length + " code units long");
                           console.log("The empty string is has a length of " + empty.length);
                           /* "The empty string is has a length of 0" */
                          -
                           
                          - -
                           
                          - -
                           
                          - -
                           
                          - -
                           
                          - -
                           
                          - -
                           
                          - -
                           
                          - -

                          规范

                          +

                          规范

                          @@ -76,7 +60,7 @@ console.log("The empty string is has a length of " + empty.length);
                          -

                          浏览器兼容性

                          +

                          浏览器兼容性

                          {{ CompatibilityTable() }}

                          @@ -84,12 +68,12 @@ console.log("The empty string is has a length of " + empty.length); - - - - - - + + + + + + @@ -107,13 +91,13 @@ console.log("The empty string is has a length of " + empty.length);
                          FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
                          Basic support
                          - - - - - - - + + + + + + + @@ -128,8 +112,8 @@ console.log("The empty string is has a length of " + empty.length);
                          FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
                          Basic support
                          -

                          相关链接

                          +

                          相关链接

                          diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html index 5991e8fa0a..e5930019f1 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/replace/index.html @@ -82,13 +82,13 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/replace 插入当前匹配的子串右边的内容。 - $n + $n

                          假如第一个参数是 {{jsxref("RegExp")}}对象,并且 n 是个小于100的非负整数,那么插入第 n 个括号匹配的字符串。提示:索引是从1开始。如果不存在第 n个分组,那么将会把匹配到到内容替换为字面量。比如不存在第3个分组,就会用“$3”替换匹配到的内容。

                          - $<Name> + $<Name>  这里Name 是一个分组名称。如果在正则表达式中并不存在分组(或者没有匹配),这个变量将被处理为空字符串。只有在支持命名分组捕获的浏览器中才能使用。 diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html index 35f5dd5736..b64952f80e 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/slice/index.html @@ -29,7 +29,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice
                          beginIndex
                          从该索引(以 0 为基数)处开始提取原字符串中的字符。如果值为负数,会被当做 strLength + beginIndex 看待,这里的strLength 是字符串的长度(例如, 如果 beginIndex 是 -3 则看作是:strLength - 3
                          endIndex
                          -
                          可选。在该索引(以 0 为基数)处结束提取字符串。如果省略该参数,slice() 会一直提取到字符串末尾。如果该参数为负数,则被看作是 strLength + endIndex,这里的 strLength 就是字符串的长度(例如,如果 endIndex 是 -3,则是, strLength - 3)。
                          +
                          可选。在该索引(以 0 为基数)处结束提取字符串。如果省略该参数,slice() 会一直提取到字符串末尾。如果该参数为负数,则被看作是 strLength + endIndex,这里的 strLength 就是字符串的长度(例如,如果 endIndex 是 -3,则是, strLength - 3)。

                          返回值

                          @@ -46,7 +46,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/slice

                          例 2:str.slice(2, -1) 提取第三个字符到倒数第一个字符。

                          -

                          例子

                          +

                          例子

                          使用 slice() 创建一个新的字符串

                          @@ -73,7 +73,7 @@ str.slice(-3, -1); // 返回 'us' str.slice(0, -1); // 返回 'The morning is upon us'
                      -

                      规范

                      +

                      规范

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html index 2aad2f2647..2fb5de2276 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/substr/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/substr
                      start
                      -
                      开始提取字符的位置。如果为负值,则被看作 strLength + start,其中 strLength 为字符串的长度(例如,如果 start-3,则被看作 strLength + (-3))。
                      +
                      开始提取字符的位置。如果为负值,则被看作 strLength + start,其中 strLength 为字符串的长度(例如,如果 start-3,则被看作 strLength + (-3))。
                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html index f556822b2e..7db9f1e146 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/string/tolowercase/index.html @@ -13,22 +13,22 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase

                      toLowerCase() 会将调用该方法的字符串值转为小写形式,并返回。

                      -

                      语法

                      +

                      语法

                      -
                      str.toLowerCase()
                      +
                      str.toLowerCase()
                       

                      返回值

                      一个新的字符串,表示转换为小写的调用字符串。

                      -

                      描述

                      +

                      描述

                      toLowerCase 会将调用该方法的字符串值转为小写形式,并返回。toLowerCase 不会影响字符串本身的值。

                      -

                      示例

                      +

                      示例

                      -

                      例子:使用 toLowerCase()

                      +

                      例子:使用 toLowerCase()

                      console.log('中文简体 zh-CN || zh-Hans'.toLowerCase());
                       // 中文简体 zh-cn || zh-hans
                      @@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase
                       ​console.log( "ALPHABET".toLowerCase() );
                       // "alphabet"
                      -
                      +

                      说明

                      diff --git a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html index 9473363551..fce5989dd7 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/symbol/index.html @@ -45,7 +45,7 @@ var sym3 = Symbol('foo');
                      var sym = new Symbol(); // TypeError
                      -

                      这会阻止创建一个显式的 Symbol 包装器对象而不是一个 Symbol 值。围绕原始数据类型创建一个显式包装器对象从 ECMAScript 6 开始不再被支持。 然而,现有的原始包装器对象,如 new Booleannew String以及new Number,因为遗留原因仍可被创建。

                      +

                      这会阻止创建一个显式的 Symbol 包装器对象而不是一个 Symbol 值。围绕原始数据类型创建一个显式包装器对象从 ECMAScript 6 开始不再被支持。 然而,现有的原始包装器对象,如 new Booleannew String以及new Number,因为遗留原因仍可被创建。

                      如果你真的想创建一个 Symbol 包装器对象 (Symbol wrapper object),你可以使用 Object() 函数:

                      @@ -201,7 +201,7 @@ obj[Object(sym)]; // still 1

                      规范

                      -
                      +
                      @@ -235,5 +235,3 @@ obj[Object(sym)]; // still 1
                    • Data types and data structures
                    • "ES6 In Depth: Symbols"(深入ES6 Symbols ) on hacks.mozilla.org
                    • - - diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html index 4e9692907a..1c335a5ffc 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/weakmap/get/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/get

                      返回值

                      -

                      返回与指定键相关联的值,如果 WeakMap 对象找不到这个键则返回 undefined

                      +

                      返回与指定键相关联的值,如果 WeakMap 对象找不到这个键则返回 undefined

                      例子

                      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 0636731b0b..47f369410f 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 @@ -31,7 +31,7 @@ translation_of: Web/JavaScript/Reference/Operators/Comma_Operator

                      示例

                      -

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

                      +

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

                      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/function/index.html b/files/zh-cn/web/javascript/reference/operators/function/index.html index bf04ca97d9..fa7ce6bd01 100644 --- a/files/zh-cn/web/javascript/reference/operators/function/index.html +++ b/files/zh-cn/web/javascript/reference/operators/function/index.html @@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Operators/function

                      描述

                      -

                      函数表达式(function expression)非常类似于函数声明(function statement)(详情查看函数声明),并且两者拥有几乎相同的语法。函数表达式与函数声明的最主要区别是函数名称(function name),在函数表达式中可省略它,从而创建匿名函数(anonymous functions)。一个函数表达式可以被用作一个IIFE(Immediately Invoked Function Expression,即时调用的函数表达式),它一旦定义就运行。更多信息请查看函数

                      +

                      函数表达式(function expression)非常类似于函数声明(function statement)(详情查看函数声明),并且两者拥有几乎相同的语法。函数表达式与函数声明的最主要区别是函数名称(function name),在函数表达式中可省略它,从而创建匿名函数(anonymous functions)。一个函数表达式可以被用作一个IIFE(Immediately Invoked Function Expression,即时调用的函数表达式),它一旦定义就运行。更多信息请查看函数

                       函数表达式提升 (Function expression hoisting)

                      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 f974698598..c84cdadf5a 100644 --- a/files/zh-cn/web/javascript/reference/operators/in/index.html +++ b/files/zh-cn/web/javascript/reference/operators/in/index.html @@ -96,7 +96,7 @@ trees[3] = undefined;
                      "toString" in {}; // 返回true
                       
                      -

                      规范

                      +

                      规范

                      标准
                      @@ -128,11 +128,11 @@ trees[3] = undefined;
                      -

                      浏览器兼容

                      +

                      浏览器兼容

                      {{Compat("javascript.operators.in")}}

                      -

                      相关链接

                      +

                      相关链接

                      • for...in
                      • 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 b4fe4061a0..d050bdb8ef 100644 --- a/files/zh-cn/web/javascript/reference/operators/typeof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/typeof/index.html @@ -23,7 +23,7 @@ translation_of: Web/JavaScript/Reference/Operators/typeof typeof(operand)
                  -

                  参数

                  +

                  参数

                  operand

                  @@ -268,7 +268,7 @@ class newClass{};
              typeof alert === 'object'
              -
              +

              相关链接

              diff --git a/files/zh-cn/web/javascript/reference/statements/debugger/index.html b/files/zh-cn/web/javascript/reference/statements/debugger/index.html index 2a54579002..0018dc056c 100644 --- a/files/zh-cn/web/javascript/reference/statements/debugger/index.html +++ b/files/zh-cn/web/javascript/reference/statements/debugger/index.html @@ -12,14 +12,14 @@ translation_of: Web/JavaScript/Reference/Statements/debugger

              语法

              -
              debugger;
              +
              debugger;
               

              示例

              下面的例子演示了一个包含 debugger 语句的函数,当函数被调用时,会尝试调用一个可用的调试器进行调试。

              -
              function potentiallyBuggyCode() {
              +
              function potentiallyBuggyCode() {
                   debugger;
                   // do potentially buggy stuff to examine, step through, etc.
               }
              diff --git a/files/zh-cn/web/javascript/reference/statements/do...while/index.html b/files/zh-cn/web/javascript/reference/statements/do...while/index.html index 714c0e807e..89a850f722 100644 --- a/files/zh-cn/web/javascript/reference/statements/do...while/index.html +++ b/files/zh-cn/web/javascript/reference/statements/do...while/index.html @@ -21,7 +21,7 @@ while (condition);
              statement
              -
              执行至少一次的语句,并在每次 condition 值为真时重新执行。想执行多行语句,可使用{{jsxref("Statements/block", "block")}}语句({ ... })包裹这些语句。
              +
              执行至少一次的语句,并在每次 condition 值为真时重新执行。想执行多行语句,可使用{{jsxref("Statements/block", "block")}}语句({ ... })包裹这些语句。
              diff --git a/files/zh-cn/web/javascript/reference/statements/for...in/index.html b/files/zh-cn/web/javascript/reference/statements/for...in/index.html index 8b3b346fcc..4bb666e930 100644 --- a/files/zh-cn/web/javascript/reference/statements/for...in/index.html +++ b/files/zh-cn/web/javascript/reference/statements/for...in/index.html @@ -27,13 +27,13 @@ translation_of: Web/JavaScript/Reference/Statements/for...in

              -

              数组迭代和 for...in

              +

              数组迭代和 for...in

              提示:for...in不应该用于迭代一个关注索引顺序的 {{jsxref("Array")}}。

              -

              仅迭代自身的属性

              +

              仅迭代自身的属性

              如果你只要考虑对象本身的属性,而不是它的原型,那么使用 {{jsxref("Object.getOwnPropertyNames", "getOwnPropertyNames()")}} 或执行 {{jsxref("Object.prototype.hasOwnProperty", "hasOwnProperty()")}} 来确定某属性是否是对象本身的属性(也能使用{{jsxref("Object.prototype.propertyIsEnumerable", "propertyIsEnumerable")}})。或者,如果你知道不会有任何外部代码干扰,您可以使用检查方法扩展内置原型。

              diff --git a/files/zh-cn/web/javascript/reference/statements/function/index.html b/files/zh-cn/web/javascript/reference/statements/function/index.html index 4d8e036a2e..be8920fca8 100644 --- a/files/zh-cn/web/javascript/reference/statements/function/index.html +++ b/files/zh-cn/web/javascript/reference/statements/function/index.html @@ -49,7 +49,7 @@ translation_of: Web/JavaScript/Reference/Statements/function

              默认情况下,函数是返回 undefined 的。想要返回一个其他的值,函数必须通过一个 return 语句指定返回值。

              -

              有条件的创建函数

              +

              有条件的创建函数

              函数可以被有条件来声明,这意味着,函数声明可能出现在一个 if 语句里,但是,这种声明方式在不同的浏览器里可能有不同的效果。因此,不应该在生产环境代码中使用这种声明方式,应该使用函数表达式来代替。

              @@ -96,7 +96,7 @@ if (true) {

              JavaScript 中的函数声明被提升到了函数定义。你可以在函数声明之前使用该函数:

              -
              hoisted(); // logs "foo"
              +
              hoisted(); // logs "foo"
               
               function hoisted() {
                 console.log('foo');
              @@ -107,7 +107,7 @@ function hoisted() {
               

              注意 :函数表达式{{jsxref("Operators/function", "function expressions")}} 不会被提升:

              -
              notHoisted(); // TypeError: notHoisted is not a function
              +
              notHoisted(); // TypeError: notHoisted is not a function
               
               var notHoisted = function() {
                 console.log('bar');
              @@ -120,11 +120,11 @@ var notHoisted = function() {
               
               

              下面的代码声明了一个函数,该函数返回了销售的总金额, 参数是产品a,b,c分别的销售的数量.

              -
              function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction
              +
              function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction
                  return units_a*79 + units_b * 129 + units_c * 699;
               }
              -

              规范

              +

              规范

              @@ -151,13 +151,13 @@ var notHoisted = function() {
              -

              浏览器兼容性

              +

              浏览器兼容性

              {{Compat("javascript.statements.function")}}

              -

              相关链接

              +

              相关链接

              • {{jsxref("Functions_and_function_scope", "Functions and function scope")}}
              • diff --git a/files/zh-cn/web/javascript/reference/statements/function_star_/index.html b/files/zh-cn/web/javascript/reference/statements/function_star_/index.html index 90794ec0d4..0ee47b290d 100644 --- a/files/zh-cn/web/javascript/reference/statements/function_star_/index.html +++ b/files/zh-cn/web/javascript/reference/statements/function_star_/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Statements/function* ---
                {{jsSidebar("Statements")}}
                -

                function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个  {{jsxref("Global_Objects/Generator","Generator")}}  对象。

                +

                function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个  {{jsxref("Global_Objects/Generator","Generator")}}  对象。

                {{EmbedInteractiveExample("pages/js/statement-functionasterisk.html")}}
                diff --git a/files/zh-cn/web/javascript/reference/strict_mode/index.html b/files/zh-cn/web/javascript/reference/strict_mode/index.html index 854e709953..c4c8dbfb7d 100644 --- a/files/zh-cn/web/javascript/reference/strict_mode/index.html +++ b/files/zh-cn/web/javascript/reference/strict_mode/index.html @@ -35,7 +35,7 @@ translation_of: Web/JavaScript/Reference/Strict_mode

                调用严格模式

                -

                严格模式可以应用到整个脚本或个别函数中。不要在封闭大括弧 {} 内这样做,在这样的上下文中这么做是没有效果的。在 eval 、Function 、内联事件处理属性、  {{domxref("WindowTimers.setTimeout()")}} 方法中传入的脚本字符串,其行为类似于开启了严格模式的一个单独脚本,它们会如预期一样工作。

                +

                严格模式可以应用到整个脚本或个别函数中。不要在封闭大括弧 {} 内这样做,在这样的上下文中这么做是没有效果的。在 eval 、Function 、内联事件处理属性、  {{domxref("WindowTimers.setTimeout()")}} 方法中传入的脚本字符串,其行为类似于开启了严格模式的一个单独脚本,它们会如预期一样工作。

                为脚本开启严格模式

                @@ -72,7 +72,7 @@ function notStrict() {

                严格模式同时改变了语法及运行时行为。变化通常分为这几类:将问题直接转化为错误(如语法错误或运行时错误), 简化了如何为给定名称的特定变量计算,简化了 eval 以及 arguments, 将写"安全“JavaScript的步骤变得更简单,以及改变了预测未来ECMAScript行为的方式。

                -

                将过失错误转成异常

                +

                将过失错误转成异常

                在严格模式下, 某些先前被接受的过失错误将会被认为是异常. JavaScript被设计为能使新人开发者更易于上手, 所以有时候会给本来错误操作赋予新的不报错误的语义(non-error semantics). 有时候这可以解决当前的问题, 但有时候却会给以后留下更大的问题. 严格模式则把这些失误当成错误, 以便可以发现并立即将其改正.

                @@ -247,7 +247,7 @@ var f = function() { return arguments.callee; }; f(); // 抛出类型错误
              -

              "安全的" JavaScript

              +

              "安全的" JavaScript

              严格模式下更容易写出“安全”的JavaScript。现在有些网站提供了方式给用户编写能够被网站其他用户执行的JavaScript代码。在浏览器环境下,JavaScript能够获取用户的隐私信息,因此这类Javascript必须在运行前部分被转换成需要申请访问禁用功能的权限。没有很多的执行时检查的情况,Javascript的灵活性让它无法有效率地做这件事。一些语言中的函数普遍出现,以至于执行时检查他们会引起严重的性能损耗。做一些在严格模式下发生的小改动,要求用户提交的JavaScript开启严格模式并且用特定的方式调用,就会大大减少在执行时进行检查的必要。

              @@ -288,7 +288,7 @@ function fun(a, b) { fun(1, 2); // 不会暴露v(或者a,或者b)
              -

              为未来的ECMAScript版本铺平道路

              +

              为未来的ECMAScript版本铺平道路

              未来版本的ECMAScript很有可能会引入新语法,ECMAScript5中的严格模式就提早设置了一些限制来减轻之后版本改变产生的影响。如果提早使用了严格模式中的保护机制,那么做出改变就会变得更容易。

              diff --git a/files/zh-cn/web/javascript/reference/template_literals/index.html b/files/zh-cn/web/javascript/reference/template_literals/index.html index ed7b7abea1..f6dcc23c02 100644 --- a/files/zh-cn/web/javascript/reference/template_literals/index.html +++ b/files/zh-cn/web/javascript/reference/template_literals/index.html @@ -13,7 +13,7 @@ original_slug: Web/JavaScript/Reference/template_strings

              模板字面量 是允许嵌入表达式的字符串字面量。你可以使用多行字符串和字符串插值功能。它们在ES2015规范的先前版本中被称为“模板字符串”。

              -

              语法

              +

              语法

              `string text`
               
              @@ -25,9 +25,9 @@ original_slug: Web/JavaScript/Reference/template_strings
               tag `string text ${expression} string text`
               
              -

              描述

              +

              描述

              -

              模板字符串使用反引号 (` `) 来代替普通字符串中的用双引号和单引号。模板字符串可以包含特定语法(${expression})的占位符。占位符中的表达式和周围的文本会一起传递给一个默认函数,该函数负责将所有的部分连接起来,如果一个模板字符串由表达式开头,则该字符串被称为带标签的模板字符串,该表达式通常是一个函数,它会在模板字符串处理后被调用,在输出最终结果前,你都可以通过该函数来对模板字符串进行操作处理。在模版字符串内使用反引号(`)时,需要在它前面加转义符(\)。

              +

              模板字符串使用反引号 (` `) 来代替普通字符串中的用双引号和单引号。模板字符串可以包含特定语法(${expression})的占位符。占位符中的表达式和周围的文本会一起传递给一个默认函数,该函数负责将所有的部分连接起来,如果一个模板字符串由表达式开头,则该字符串被称为带标签的模板字符串,该表达式通常是一个函数,它会在模板字符串处理后被调用,在输出最终结果前,你都可以通过该函数来对模板字符串进行操作处理。在模版字符串内使用反引号(`)时,需要在它前面加转义符(\)。

              `\`` === "`" // --> true
              @@ -216,7 +216,7 @@ latex`\unicode`
              let bad = `bad escape sequence: \unicode`;
              -

              规范

              +

              规范

              @@ -243,7 +243,7 @@ latex`\unicode`
              -

              浏览器兼容

              +

              浏览器兼容

              @@ -251,7 +251,7 @@ latex`\unicode`

              {{Compat("javascript.grammar.template_literals")}}

              -

              相关链接

              +

              相关链接

              • {{jsxref("String")}}
              • -- cgit v1.2.3-54-g00ecf