Skip to content

Commit d458c2c

Browse files
authored
Sync with upstream @ 3dd8ca0 (#42)
* modified sub headings for clarity and to avoid confusion * Update article.md * Update task.md fix typo * Update article.md Change to wording about maximum recursion depth. * Update article.md * Update article.md Correct spelling of "standardized". * Fix typo * minor * closes #1271 * minor * clarify type conversion headings * minor * improve description Change the order between ´body´ and ´step´. Also delete the phrase '... but before the condition check', which seems a bit confusing. * Update article.md Maybe this is what you want. "Complexity" is singular, so if that's the antecedent, one would use "was". * fixes #1261 * Fix typo fix typo in comment to match code example * Typo/grammar fix * fixed missing pronoun 'it' fixed missing pronoun 'it'. * fixed missing pronoun 'it' fixed missing pronoun 'it' * Update article.md fixed grammaticalmistakes, i.e. changed 'And' to 'and', added missing pronoun 'it' after 'to'. * Update article.md * Fixed spelling error So here JavaScript assumes that we have a code block, but why there's an error. --> Makes no sense so replaced "but" with "that's" * fixes * minor * Update article.md Better grammatically. * typo * minor * fixes * fix minor English language issues * fix typo * Some minor corrections * Is it * Update article.md Wording of initial explanation of spread operator. * Typo * there must be exactly the origin there. * Fixed a typo * Update article.md 1. Since is general statement, thought might be better to use general function name. 2. "Do the following steps" is a bit awkward, in that usually one doesn't "do" steps (but rather "takes", or "follows", or "executes" steps, perhaps). But it does convey the meaning, and perhaps it's a relatively new usage in business or tech that I'm not familiar with. For me, it comes off a bit awkward. Leaving out "steps" works grammatically and preserves the sense. Or could find another verb to replace "do" -- but nothing perfect came to mind. Not that bad the way it is, but since I was already changing the sentence... * Update article.md Says "is the same object as:", but what's below is an assignment (that includes an object). I didn't have any problem understanding it, didn't even notice it at first, but I thought it would be more accurate this way without sacrificing clarity. * Update article.md Qualify that while cachingDecorator() will now work with any number of arguments, the hash() function given will not. Or, perhaps better, could just change the hash function to something like: function hash(args) { return [...args].join(); } * Update article.md * minor * fixes * grammar fix removed 'is' * minor * minor * minor * minor * minor * minor * minor * minor * closes #1310 * closes #1309 * closes #1309 * closes #1309 * minor * closes #1308 * closes #1294 * Fix typo in Proxy and Reflect article * Update task.md Wording was ungrammatical and hard to understand. I made my best guess as to what you want to say. However, it is not clear from the description or the examples whether the debounce wrapper should inhibit calls attempted ms milliseconds after the last call that wasn't ignored, or ms milliseconds after the last call that was attempted, even if it was ignored. I would think it would be the former, but the example could go either way. If the f(4) example used 1000 or 1001 ms and still runs, that would clear it up. If it has to be 1100 like it is, that would suggest that it's the second scenario above. In my propsed change I preserved the ambiguity. * closes #1220 * Update MDN docs link for tagged templates * Update article.md As per issue comment thread #1282: Clarifying "current code" for zero delay setInterval. Plus minor edit of ordering of terms for greater consistency. Plus minor grammatical fixes. * an -> a * WIP * fixes #1316 * closes #1318 * minor * minor * WIP * WIP * regexp * WIP * reg->regexp * WIP * Typo fix * minor * form * Typo fix * fixes * fixes * fix * Fix minor grammatical errors * Minor grammatical fixes * minor
1 parent 4807103 commit d458c2c

File tree

103 files changed

+2599
-2309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2599
-2309
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# 手冊以及規格書
1+
# 操作手冊和規格書
22

3-
這本書是個 _教程_,主要是幫助你漸漸地學會這門語言,一旦你熟悉了基礎,你將會需要更多其他的資源來幫助你
3+
這本書是個 *教程*,主要是幫助你漸漸地學會這門語言,一旦你熟悉了基礎,你將會需要更多其他的資源
44

55
## 規格書
66

@@ -12,17 +12,17 @@
1212

1313
如果你想知道最尖端的功能,包含那些 "即將成為標準"(所謂 "stage 3")的功能,可以看一下 <https://github.com/tc39/proposals>
1414

15-
或者,假如你在開發瀏覽器相關的功能,我們也有在此教程的 [第二部分](info:browser-environment) 介紹相關的規格書。
15+
同樣地,假如你在開發瀏覽器相關的功能,我們也有在此教程的 [第二部分](info:browser-environment) 介紹相關的規格書。
1616

17-
## 手冊
17+
## 操作手冊
1818

19-
- **MDN (Mozilla) JavaScript Reference** 是一個包含了範例以及其他資訊的手冊,很適合拿來獲取個別函式或是方法的深入資訊。
19+
- **MDN (Mozilla) JavaScript Reference** 是一個包含了範例以及其他資訊的操作手冊,很適合拿來獲取個別函式或是方法的深入資訊。
2020

2121
你可以在這裡找到 <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>
2222

2323
不過,透過網路搜尋通常會是較好的選擇。使用在搜尋列打入 "MDN [關鍵字]" 的方式,比如你要搜尋 `parseInt` 這個函式,可以用 <https://google.com/search?q=MDN+parseInt>
2424

25-
* **MSDN**微軟釋出的手冊,包含了一堆 JavaScript(通常是指 JScript)的資訊。如果你需要開發跟 Internet Explorer 有關的功能,最好參考此處: <http://msdn.microsoft.com/>
25+
- **MSDN**微軟釋出的操作手冊,包含了一堆 JavaScript(通常是指 JScript)的資訊。如果你需要開發跟 Internet Explorer 有關的功能,最好參考此處: <http://msdn.microsoft.com/>
2626

2727
當然,我們也可以透過網路搜尋來找到我們需要的資訊,比如 "RegExp MSDN" 或是 "RegExp MSDN jscript"。
2828

@@ -32,9 +32,10 @@ JavaScript 是一個持續開發中的語言,它定期會被加入一些新功
3232

3333
想知道瀏覽器或是其他引擎的支援程度,可以參考:
3434

35-
- <http://caniuse.com> - 列出每一個功能的支援程度,比如:查找哪個引擎支援現代的編碼功能:<http://caniuse.com/#feat=cryptography>
36-
- <https://kangax.github.io/compat-table> - 一個列出所有功能以及每個引擎支援程度的表。
35+
- <http://caniuse.com> - 列出每一個功能的支援程度,比如:查找哪個引擎支援現代的編碼功能:<http://caniuse.com/#feat=cryptography>
36+
- <https://kangax.github.io/compat-table> - 一個列出所有功能以及每個引擎支援程度的表。
3737

3838
所有這些資訊對於實務開發都是很有用的,因為他們包含了非常有價值的資訊,比如支援程度跟語言的細節等。
3939

4040
當你需要比較深入的資訊或是需要了解一些特定的功能時,請記得使用這些資訊(或是此頁)。
41+

1-js/02-first-steps/06-type-conversions/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ alert( Boolean(" ") ); // 空白,也是 true(任何非空字串都是 true
128128
129129
三種最為廣泛使用的類型轉換是:轉字串、轉數值和轉布林。
130130
131-
**`String Conversion`** -- 用於當我們輸出某些東西時,可使用 `String(value)` 來轉換,原生值的字串轉換通常是很直觀的。
131+
**`字串轉換`** -- 用於當我們輸出某些東西時,可使用 `String(value)` 來轉換,原生值的字串轉換通常是很直觀的。
132132
133-
**`Numeric Conversion`** -- 用於數學運算,可使用 `Number(value)` 來轉換。
133+
**`數值轉換`** -- 用於數學運算,可使用 `Number(value)` 來轉換。
134134
135135
按照以下規則轉換:
136136
@@ -141,7 +141,7 @@ alert( Boolean(" ") ); // 空白,也是 true(任何非空字串都是 true
141141
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
142142
| `string` | 字串 "依原樣" 讀取並忽略頭尾空白,若為空字串則為 `0`,有錯誤則成為 `NaN`。 |
143143
144-
**`Boolean Conversion`** -- 用於邏輯運算,可使用 `Boolean(value)` 來轉換。
144+
**`布林轉換`** -- 用於邏輯運算,可使用 `Boolean(value)` 來轉換。
145145
146146
規則是:
147147

1-js/02-first-steps/07-operators/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
alert( y - x ); // 2,二元減號運算子套用減法
2727
```
2828

29-
正式地說,這邊提及的是兩種使用同個符號,意義卻完全不同的運算子:一元負號運算子(單一個運算元,正負轉換)和二元減號運算子(兩個運算元,減法)。
29+
正式地說,上例中的兩個運算子使用同一個符號,但意義卻完全不同:一元負號運算子(單一個運算元,正負轉換)和二元減號運算子(兩個運算元,一對一的數值減法)。
3030

3131
## 字串連接,二元運算子 +
3232

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ It's common that an object method needs to access the information stored in the
9898

9999
For instance, the code inside `user.sayHi()` may need the name of the `user`.
100100

101-
**To access the object, a method can use the `this` keyword.**
101+
**To access the object, a method can use `this` keyword.**
102102

103103
The value of `this` is the object "before dot", the one used to call the method.
104104

@@ -167,9 +167,9 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
167167

168168
## "this" is not bound
169169

170-
In JavaScript, "this" keyword behaves unlike most other programming languages. It can be used in any function.
170+
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function.
171171

172-
There's no syntax error in the code like that:
172+
There's no syntax error in the following example:
173173

174174
```js
175175
function sayHi() {
@@ -220,13 +220,13 @@ In this case `this` is `undefined` in strict mode. If we try to access `this.nam
220220

221221
In non-strict mode the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later in the chapter [](info:global-object)). This is a historical behavior that `"use strict"` fixes.
222222

223-
Usually such call is an programming error. If there's `this` inside a function, it expects to be called in an object context.
223+
Usually such call is a programming error. If there's `this` inside a function, it expects to be called in an object context.
224224
````
225225
226226
```smart header="The consequences of unbound `this`"
227227
If you come from another programming language, then you are probably used to the idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.
228228
229-
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what's the object "before the dot".
229+
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is "before the dot".
230230
231231
The concept of run-time evaluated `this` has both pluses and minuses. On the one hand, a function can be reused for different objects. On the other hand, greater flexibility opens a place for mistakes.
232232

1-js/05-data-types/01-primitives-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The solution looks a little bit awkward, but here it is:
5050

5151
The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean` and `Symbol`. Thus, they provide different sets of methods.
5252

53-
For instance, there exists a method [str.toUpperCase()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) that returns a capitalized string.
53+
For instance, there exists a string method [str.toUpperCase()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) that returns a capitalized `str`.
5454

5555
Here's how it works:
5656

1-js/05-data-types/03-string/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let guestList = "Guests: // Error: Unexpected token ILLEGAL
5050

5151
Single and double quotes come from ancient times of language creation when the need for multiline strings was not taken into account. Backticks appeared much later and thus are more versatile.
5252

53-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_template_literals). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
53+
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_templates). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
5454

5555
## Special characters
5656

1-js/05-data-types/05-array-methods/article.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,31 +655,37 @@ arr.map(func, thisArg);
655655

656656
The value of `thisArg` parameter becomes `this` for `func`.
657657

658-
For instance, here we use an object method as a filter and `thisArg` helps with that:
658+
For example, here we use a method of `army` object as a filter, and `thisArg` passes the context:
659659

660660
```js run
661-
let user = {
662-
age: 18,
663-
younger(otherUser) {
664-
return otherUser.age < this.age;
661+
let army = {
662+
minAge: 18,
663+
maxAge: 27,
664+
canJoin(user) {
665+
return user.age >= this.minAge && user.age < this.maxAge;
665666
}
666667
};
667668

668669
let users = [
669-
{age: 12},
670670
{age: 16},
671-
{age: 32}
671+
{age: 20},
672+
{age: 23},
673+
{age: 30}
672674
];
673675

674676
*!*
675-
// find all users younger than user
676-
let youngerUsers = users.filter(user.younger, user);
677+
// find users, for who army.canJoin returns true
678+
let soldiers = users.filter(army.canJoin, army);
677679
*/!*
678680

679-
alert(youngerUsers.length); // 2
681+
alert(soldiers.length); // 2
682+
alert(soldiers[0].age); // 20
683+
alert(soldiers[1].age); // 23
680684
```
681685

682-
In the call above, we use `user.younger` as a filter and also provide `user` as the context for it. If we didn't provide the context, `users.filter(user.younger)` would call `user.younger` as a standalone function, with `this=undefined`. That would mean an instant error.
686+
If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error.
687+
688+
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The former is used more often, as it's a bit easier to understand for most people.
683689

684690
## Summary
685691

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ alert(item1); // Cake
403403
alert(item2); // Donut
404404
```
405405
406-
The whole `options` object except `extra` that was not mentioned, is assigned to corresponding variables:
406+
All properties of `options` object except `extra` that is absent in the left part, are assigned to corresponding variables:
407407
408408
![](destructuring-complex.svg)
409409

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ We may decide to execute a function not right now, but at a certain time later.
44

55
There are two methods for it:
66

7-
- `setTimeout` allows to run a function once after the interval of time.
8-
- `setInterval` allows to run a function regularly with the interval between the runs.
7+
- `setTimeout` allows us to run a function once after the interval of time.
8+
- `setInterval` allows us to run a function repeatedly, starting after the interval of time, then repeating continuously at that interval.
99

1010
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.js.
1111

@@ -239,9 +239,9 @@ There's a side-effect. A function references the outer lexical environment, so,
239239

240240
There's a special use case: `setTimeout(func, 0)`, or just `setTimeout(func)`.
241241

242-
This schedules the execution of `func` as soon as possible. But scheduler will invoke it only after the current code is complete.
242+
This schedules the execution of `func` as soon as possible. But the scheduler will invoke it only after the currently executing script is complete.
243243

244-
So the function is scheduled to run "right after" the current code.
244+
So the function is scheduled to run "right after" the current script.
245245

246246
For instance, this outputs "Hello", then immediately "World":
247247

@@ -251,7 +251,7 @@ setTimeout(() => alert("World"));
251251
alert("Hello");
252252
```
253253

254-
The first line "puts the call into calendar after 0ms". But the scheduler will only "check the calendar" after the current code is complete, so `"Hello"` is first, and `"World"` -- after it.
254+
The first line "puts the call into calendar after 0ms". But the scheduler will only "check the calendar" after the current script is complete, so `"Hello"` is first, and `"World"` -- after it.
255255

256256
There are also advanced browser-related use cases of zero-delay timeout, that we'll discuss in the chapter <info:event-loop>.
257257

@@ -286,10 +286,10 @@ For server-side JavaScript, that limitation does not exist, and there exist othe
286286

287287
## Summary
288288

289-
- Methods `setInterval(func, delay, ...args)` and `setTimeout(func, delay, ...args)` allow to run the `func` regularly/once after `delay` milliseconds.
290-
- To cancel the execution, we should call `clearInterval/clearTimeout` with the value returned by `setInterval/setTimeout`.
291-
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`, allowing to set the time *between* executions more precisely.
292-
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current code is complete".
289+
- Methods `setTimeout(func, delay, ...args)` and `setInterval(func, delay, ...args)` allow us to run the `func` once/regularly after `delay` milliseconds.
290+
- To cancel the execution, we should call `clearTimeout/clearInterval` with the value returned by `setTimeout/setInterval`.
291+
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`, allowing us to set the time *between* executions more precisely.
292+
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current script is complete".
293293
- The browser limits the minimal delay for five or more nested call of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
294294

295295
Please note that all scheduling methods do not *guarantee* the exact delay.

1-js/06-advanced-functions/09-call-apply-decorators/03-debounce/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
The result of `debounce(f, ms)` decorator should be a wrapper that passes the call to `f` at maximum once per `ms` milliseconds.
88

9-
In other words, when we call a "debounced" function, it guarantees that all other future in the closest `ms` milliseconds will be ignored.
9+
In other words, when we call a "debounced" function, it guarantees that all future calls to the function made less than `ms` milliseconds after the previous call will be ignored.
1010

1111
For instance:
1212

@@ -21,4 +21,4 @@ setTimeout( () => f(4), 1100); // runs
2121
setTimeout( () => f(5), 1500); // ignored (less than 1000 ms from the last run)
2222
```
2323

24-
In practice `debounce` is useful for functions that retrieve/update something when we know that nothing new can be done in such a short period of time, so it's better not to waste resources.
24+
In practice `debounce` is useful for functions that retrieve/update something when we know that nothing new can be done in such a short period of time, so it's better not to waste resources.

0 commit comments

Comments
 (0)