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() {
File renamed without changes.
File renamed without changes.
File renamed without changes.

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.

0 commit comments

Comments
 (0)