Skip to content

Commit 186dfa6

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-e4e6a50b
2 parents 4641ff0 + e4e6a50 commit 186dfa6

File tree

14 files changed

+63
-15
lines changed

14 files changed

+63
-15
lines changed

1-js/05-data-types/09-keys-values-entries/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Usually that's convenient. But if we want symbolic keys too, then there's a sepa
7474

7575
Objects lack many methods that exist for arrays, e.g. `map`, `filter` and others.
7676

77-
If we'd like to apply them, then we can use `Object.entries` followed `Object.fromEntries`:
77+
If we'd like to apply them, then we can use `Object.entries` followed by `Object.fromEntries`:
7878

7979
1. Use `Object.entries(obj)` to get an array of key/value pairs from `obj`.
8080
2. Use array methods on that array, e.g. `map`.

1-js/06-advanced-functions/03-closure/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Rectangles on the right-hand side demonstrate how the global Lexical Environment
183183

184184
1. When the script starts, the Lexical Environment is pre-populated with all declared variables.
185185
- Initially, they are in the "Uninitialized" state. That's a special internal state, it means that the engine knows about the variable, but it cannot be referenced until it has been declared with `let`. It's almost the same as if the variable didn't exist.
186-
2. Then `let phrase` definition appears. There's no assignment yet, so its value is `undefined`. We can use the variable since this moment.
186+
2. Then `let phrase` definition appears. There's no assignment yet, so its value is `undefined`. We can use the variable from this point forward.
187187
3. `phrase` is assigned a value.
188188
4. `phrase` changes the value.
189189

@@ -286,7 +286,7 @@ Later, when `counter()` is called, a new Lexical Environment is created for the
286286

287287
![](closure-makecounter-nested-call.svg)
288288

289-
Now when the code inside `counter()` looks for `count` variable, it first searches its own Lexical Environment (empty, as there are no local variables there), then the Lexical Environment of the outer `makeCounter()` call, where finds it and changes.
289+
Now when the code inside `counter()` looks for `count` variable, it first searches its own Lexical Environment (empty, as there are no local variables there), then the Lexical Environment of the outer `makeCounter()` call, where it finds and changes it.
290290

291291
**A variable is updated in the Lexical Environment where it lives.**
292292

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function sum(a) {
2+
3+
let currentSum = a;
4+
5+
function f(b) {
6+
currentSum += b;
7+
return f;
8+
}
9+
10+
f.toString = function() {
11+
return currentSum;
12+
};
13+
14+
return f;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function sum(a){
2+
// Your code goes here.
3+
4+
}
5+
6+
/*
7+
sum(1)(2) == 3; // 1 + 2
8+
sum(1)(2)(3) == 6; // 1 + 2 + 3
9+
sum(5)(-1)(2) == 6
10+
sum(6)(-1)(-2)(-3) == 0
11+
sum(0)(1)(2)(3)(4)(5) == 15
12+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe("sum", function(){
2+
3+
it("sum(1)(2) == 3", function(){
4+
assert.equal(3, sum(1)(2));
5+
});
6+
7+
it("sum(5)(-1)(2) == 6", function(){
8+
assert.equal(6, sum(5)(-1)(2));
9+
});
10+
11+
it("sum(6)(-1)(-2)(-3) == 0", function(){
12+
assert.equal(0, sum(6)(-1)(-2)(-3));
13+
});
14+
15+
it("sum(0)(1)(2)(3)(4)(5) == 15", function(){
16+
assert.equal(15, sum(0)(1)(2)(3)(4)(5));
17+
});
18+
});
19+

1-js/06-advanced-functions/09-call-apply-decorators/04-throttle/_js.view/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe("throttle(f, 1000)", function() {
77
}
88

99
before(function() {
10-
f1000 = throttle(f, 1000);
1110
this.clock = sinon.useFakeTimers();
11+
f1000 = throttle(f, 1000);
1212
});
1313

1414
it("the first call runs now", function() {

1-js/11-async/05-promise-api/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ If the browser doesn't support `Promise.allSettled`, it's easy to polyfill:
179179
if(!Promise.allSettled) {
180180
Promise.allSettled = function(promises) {
181181
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
182-
state: 'fulfilled',
182+
status: 'fulfilled',
183183
value
184184
}), reason => ({
185-
state: 'rejected',
185+
status: 'rejected',
186186
reason
187187
}))));
188188
};
@@ -191,7 +191,7 @@ if(!Promise.allSettled) {
191191
192192
In this code, `promises.map` takes input values, turns them into promises (just in case a non-promise was passed) with `p => Promise.resolve(p)`, and then adds `.then` handler to every one.
193193
194-
That handler turns a successful result `value` into `{state:'fulfilled', value}`, and an error `reason` into `{state:'rejected', reason}`. That's exactly the format of `Promise.allSettled`.
194+
That handler turns a successful result `value` into `{status:'fulfilled', value}`, and an error `reason` into `{status:'rejected', reason}`. That's exactly the format of `Promise.allSettled`.
195195
196196
Now we can use `Promise.allSettled` to get the results of *all* given promises, even if some of them reject.
197197
@@ -277,7 +277,7 @@ There are 5 static methods of `Promise` class:
277277
278278
1. `Promise.all(promises)` -- waits for all promises to resolve and returns an array of their results. If any of the given promises rejects, it becomes the error of `Promise.all`, and all other results are ignored.
279279
2. `Promise.allSettled(promises)` (recently added method) -- waits for all promises to settle and returns their results as an array of objects with:
280-
- `state`: `"fulfilled"` or `"rejected"`
280+
- `status`: `"fulfilled"` or `"rejected"`
281281
- `value` (if fulfilled) or `reason` (if rejected).
282282
3. `Promise.race(promises)` -- waits for the first promise to settle, and its result/error becomes the outcome.
283283
4. `Promise.resolve(value)` -- makes a resolved promise with the given value.

2-ui/1-document/11-coordinates/article.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ function getCoords(elem) {
216216
217217
return {
218218
top: box.top + window.pageYOffset,
219+
right: box.right + window.pageXOffset,
220+
bottom: box.bottom + window.pageYOffset,
219221
left: box.left + window.pageXOffset
220222
};
221223
}

2-ui/3-event-details/6-pointer-events/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ But we continue tracking track `pointermove` events and move the thumb until `po
177177

178178
[Previously](info:mouse-drag-and-drop), to handle `pointermove` events that happen outside of the slider, we listened for `pointermove` events on the whole `document`.
179179

180-
Pointer capturing provides an alternative solution: we can call `thumb.setPointerCapture(event.pointerId)` in `pointerdown` handler, and then all future pointer events until `pointerup` will be retarteted to `thumb`.
180+
Pointer capturing provides an alternative solution: we can call `thumb.setPointerCapture(event.pointerId)` in `pointerdown` handler, and then all future pointer events until `pointerup` will be retargeted to `thumb`.
181181

182182
That is: events handlers on `thumb` will be called, and `event.target` will always be `thumb`, even if the user moves their pointer around the whole document. So we can listen at `thumb` for `pointermove`, no matter where it happens.
183183

@@ -226,4 +226,4 @@ Additional abilities of Pointer events are:
226226
- Device-specific properties, such as `pressure`, `width/height` and others.
227227
- Pointer capturing: we can retarget all pointer events to a specific element until `pointerup`/`pointercancel`.
228228

229-
As of now, pointer events are supported in all major browsers, so we can safely switch to them, if IE10- and Safari 12- are not needed. And even with those browsers, there are polyfills that enable the support of pointer events.
229+
As of now, pointer events are supported in all major browsers, so we can safely switch to them, if IE10- and Safari 12- are not needed. And even with those browsers, there are polyfills that enable the support of pointer events.

6-data-storage/03-indexeddb/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ libs:
55

66
# IndexedDB
77

8-
IndexedDB is a database, that is built into browser, much more powerful than `localStorage`.
8+
IndexedDB is a database that is built into browser, much more powerful than `localStorage`.
99

1010
- Stores almost any kind of values by keys, multiple key types.
1111
- Supports transactions for reliability.
@@ -75,10 +75,10 @@ We can open it with version `2` and perform the upgrade like this:
7575
```js
7676
let openRequest = indexedDB.open("store", *!*2*/!*);
7777

78-
openRequest.onupgradeneeded = function() {
78+
openRequest.onupgradeneeded = function(event) {
7979
// the existing database version is less than 2 (or it doesn't exist)
8080
let db = openRequest.result;
81-
switch(db.version) { // existing db version
81+
switch(event.oldVersion) { // existing db version
8282
case 0:
8383
// version 0 means that the client had no database
8484
// perform initialization

9-regular-expressions/03-regexp-unicode/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Here's the main character categories and their subcategories:
9393
- control `Cc`,
9494
- format `Cf`,
9595
- not assigned `Cn`,
96-
-- private use `Co`,
96+
- private use `Co`,
9797
- surrogate `Cs`.
9898

9999

@@ -127,7 +127,7 @@ alert("number: xAF".match(regexp)); // xAF
127127

128128
Let's look for Chinese hieroglyphs.
129129

130-
There's a unicode property `Script` (a writing system), that may have a value: `Cyrillic`, `Greek`, `Arabic`, `Han` (Chinese) and so on, [here's the full list]("https://en.wikipedia.org/wiki/Script_(Unicode)").
130+
There's a unicode property `Script` (a writing system), that may have a value: `Cyrillic`, `Greek`, `Arabic`, `Han` (Chinese) and so on, [here's the full list](https://en.wikipedia.org/wiki/Script_(Unicode)).
131131

132132
To look for characters in a given writing system we should use `pattern:Script=<value>`, e.g. for Cyrillic letters: `pattern:\p{sc=Cyrillic}`, for Chinese hieroglyphs: `pattern:\p{sc=Han}`, and so on:
133133

0 commit comments

Comments
 (0)