@@ -34,29 +34,29 @@ ECMAScript 6规格的26章之中,第1章到第3章是对文件本身的介绍
34
34
35
35
规格对每一种语法行为的描述,都分成两部分:先是总体的行为描述,然后是实现的算法细节。相等运算符的总体描述,只有一句话。
36
36
37
- > “The comparison ` x == y ` , where x and y are values, produces ` true ` or ` false ` .”
37
+ > “The comparison ` x == y ` , where ` x ` and ` y ` are values, produces ` true ` or ` false ` .”
38
38
39
39
上面这句话的意思是,相等运算符用于比较两个值,返回` true ` 或` false ` 。
40
40
41
41
下面是算法细节。
42
42
43
43
> 1 . ReturnIfAbrupt(x).
44
44
> 1 . ReturnIfAbrupt(y).
45
- > 1 . If Type(x) is the same as Type(y), then
46
- > Return the result of performing Strict Equality Comparison x === y.
47
- > 1 . If x is null and y is undefined, return true.
48
- > 1 . If x is undefined and y is null, return true.
49
- > 1 . If Type(x) is Number and Type(y) is String,
50
- > return the result of the comparison x == ToNumber(y).
51
- > 1 . If Type(x) is String and Type(y) is Number,
45
+ > 1 . If ` Type(x) ` is the same as ` Type(y) ` , then
46
+ > Return the result of performing Strict Equality Comparison ` x === y ` .
47
+ > 1 . If ` x ` is ` null ` and ` y ` is ` undefined ` , return ` true ` .
48
+ > 1 . If ` x ` is ` undefined ` and ` y ` is ` null ` , return ` true ` .
49
+ > 1 . If ` Type(x) ` is Number and ` Type(y) ` is String,
50
+ > return the result of the comparison ` x == ToNumber(y) ` .
51
+ > 1 . If ` Type(x) ` is String and ` Type(y) ` is Number,
52
52
> return the result of the comparison ToNumber(x) == y.
53
- > 1 . If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
54
- > 1 . If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
55
- > 1 . If Type(x) is either String, Number, or Symbol and Type(y) is Object, then
56
- > return the result of the comparison x == ToPrimitive(y).
57
- > 1 . If Type(x) is Object and Type(y) is either String, Number, or Symbol, then
58
- > return the result of the comparison ToPrimitive(x) == y.
59
- > 1 . Return false.
53
+ > 1 . If ` Type(x) ` is Boolean, return the result of the comparison ` ToNumber(x) == y ` .
54
+ > 1 . If ` Type(y) ` is Boolean, return the result of the comparison ` x == ToNumber(y) ` .
55
+ > 1 . If ` Type(x) ` is either String, Number, or Symbol and ` Type(y) ` is Object, then
56
+ > return the result of the comparison ` x == ToPrimitive(y) ` .
57
+ > 1 . If ` Type(x) ` is Object and ` Type(y) ` is either String, Number, or Symbol, then
58
+ > return the result of the comparison ` ToPrimitive(x) == y ` .
59
+ > 1 . Return ` false ` .
60
60
61
61
上面这段算法,一共有12步,翻译如下。
62
62
@@ -138,7 +138,7 @@ a2.map(n => 1) // [, , ,]
138
138
139
139
后面的算法描述是这样的。
140
140
141
- > 1 . Let O be ToObject(this value).
141
+ > 1 . Let ` O ` be ` ToObject(this value) ` .
142
142
> 1 . ReturnIfAbrupt(O).
143
143
> 1 . Let len be ToLength(Get(O, "length")).
144
144
> 1 . ReturnIfAbrupt(len).
@@ -147,17 +147,17 @@ a2.map(n => 1) // [, , ,]
147
147
> 1 . Let A be ArraySpeciesCreate(O, len).
148
148
> 1 . ReturnIfAbrupt(A).
149
149
> 1 . Let k be 0.
150
- > 1 . Repeat, while k < len
151
- > a. Let Pk be ToString(k).
152
- > b. Let kPresent be HasProperty(O, Pk).
153
- > c. ReturnIfAbrupt(kPresent).
154
- > d. If kPresent is true, then
155
- > d-1. Let kValue be Get(O, Pk).
156
- > d-2. ReturnIfAbrupt(kValue).
157
- > d-3. Let mappedValue be Call(callbackfn, T, «kValue, k, O»).
158
- > d-4. ReturnIfAbrupt(mappedValue).
159
- > d-5. Let status be CreateDataPropertyOrThrow (A, Pk, mappedValue).
160
- > d-6. ReturnIfAbrupt(status).
150
+ > 1 . Repeat, while k < len
151
+ > a. Let Pk be ToString(k).
152
+ > b. Let kPresent be HasProperty(O, Pk).
153
+ > c. ReturnIfAbrupt(kPresent).
154
+ > d. If kPresent is true, then
155
+ > d-1. Let kValue be Get(O, Pk).
156
+ > d-2. ReturnIfAbrupt(kValue).
157
+ > d-3. Let mappedValue be Call(callbackfn, T, «kValue, k, O»).
158
+ > d-4. ReturnIfAbrupt(mappedValue).
159
+ > d-5. Let status be CreateDataPropertyOrThrow (A, Pk, mappedValue).
160
+ > d-6. ReturnIfAbrupt(status).
161
161
> e. Increase k by 1.
162
162
> 1 . Return A.
163
163
@@ -172,17 +172,17 @@ a2.map(n => 1) // [, , ,]
172
172
> 1 . 生成一个新的数组` A ` ,跟当前数组的` length ` 属性保持一致
173
173
> 1 . 如果报错就返回
174
174
> 1 . 设定` k ` 等于0
175
- > 1 . 只要` k ` 小于当前数组的` length ` 属性,就重复下面步骤
176
- > a. 设定` Pk ` 等于` ToString(k) ` ,即将` K ` 转为字符串
177
- > b. 设定` kPresent ` 等于` HasProperty(O, Pk) ` ,即求当前数组有没有指定属性
178
- > c. 如果报错就返回
179
- > d. 如果` kPresent ` 等于` true ` ,则进行下面步骤
180
- > d-1. 设定` kValue ` 等于` Get(O, Pk) ` ,取出当前数组的指定属性
181
- > d-2. 如果报错就返回
182
- > d-3. 设定` mappedValue ` 等于` Call(callbackfn, T, «kValue, k, O») ` ,即执行回调函数
183
- > d-4. 如果报错就返回
184
- > d-5. 设定` status ` 等于` CreateDataPropertyOrThrow (A, Pk, mappedValue) ` ,即将回调函数的值放入` A ` 数组的指定位置
185
- > d-6. 如果报错就返回
175
+ > 1 . 只要` k ` 小于当前数组的` length ` 属性,就重复下面步骤
176
+ > a. 设定` Pk ` 等于` ToString(k) ` ,即将` K ` 转为字符串
177
+ > b. 设定` kPresent ` 等于` HasProperty(O, Pk) ` ,即求当前数组有没有指定属性
178
+ > c. 如果报错就返回
179
+ > d. 如果` kPresent ` 等于` true ` ,则进行下面步骤
180
+ > d-1. 设定` kValue ` 等于` Get(O, Pk) ` ,取出当前数组的指定属性
181
+ > d-2. 如果报错就返回
182
+ > d-3. 设定` mappedValue ` 等于` Call(callbackfn, T, «kValue, k, O») ` ,即执行回调函数
183
+ > d-4. 如果报错就返回
184
+ > d-5. 设定` status ` 等于` CreateDataPropertyOrThrow (A, Pk, mappedValue) ` ,即将回调函数的值放入` A ` 数组的指定位置
185
+ > d-6. 如果报错就返回
186
186
> e. ` k ` 增加1
187
187
> 1 . 返回` A `
188
188
0 commit comments