Skip to content

Commit a91a281

Browse files
authored
Merge pull request #88 from javascript-tutorial/sync-e4e6a50b
Sync with upstream @ e4e6a50
2 parents 3d9ac01 + b7a7f68 commit a91a281

14 files changed

Lines changed: 63 additions & 15 deletions

File tree

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/09-classes/02-class-inheritance/3-class-extend-object/rabbit-extends-object.svg renamed to 1-js/09-classes/03-static-properties-methods/3-class-extend-object/rabbit-extends-object.svg

File renamed without changes.

1-js/09-classes/02-class-inheritance/3-class-extend-object/solution.md renamed to 1-js/09-classes/03-static-properties-methods/3-class-extend-object/solution.md

File renamed without changes.

1-js/09-classes/02-class-inheritance/3-class-extend-object/task.md renamed to 1-js/09-classes/03-static-properties-methods/3-class-extend-object/task.md

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
@@ -181,10 +181,10 @@ Promise.allSettled(urls.map(url => fetch(url)))
181181
if(!Promise.allSettled) {
182182
Promise.allSettled = function(promises) {
183183
return Promise.all(promises.map(p => Promise.resolve(p).then(value => ({
184-
state: 'fulfilled',
184+
status: 'fulfilled',
185185
value
186186
}), reason => ({
187-
state: 'rejected',
187+
status: 'rejected',
188188
reason
189189
}))));
190190
};
@@ -193,7 +193,7 @@ if(!Promise.allSettled) {
193193
194194
في هذا الرمز ، يأخذ `promises.map` قيم الإدخال ، ويحولها إلى وعود (فقط في حالة تمرير عدم الوعد) مع` p => Promise.resolve (p) `، ثم يضيف معالج` .then` إلى كل واحد.
195195
196-
يحول هذا المعالج نتيجة "القيمة" الناجحة إلى "{state:" الوفاء "و value}` والخطأ "reason" إلى "{state: "رفض"، reason} `. هذا هو بالضبط تنسيق `Promise.allSettled`.
196+
يحول هذا المعالج نتيجة `القيمة` الناجحة إلى `{status:'fulfilled', value}` والخطأ `reason` إلى `{status:'rejected', reason}`. هذا هو بالضبط تنسيق `Promise.allSettled`.
197197
198198
الآن يمكننا استخدام "Promise.allSettled" للحصول على نتائج * جميع * الوعود المعطاة ، حتى لو رفض بعضها.
199199
@@ -285,4 +285,4 @@ let promise = new Promise((resolve, reject) => reject(error));
285285
4. "Promise.resolve (القيمة)" - يقدم وعدًا ثابتًا بقيمة معينة.
286286
5. "Promise.reject (خطأ)" - يقدم وعدًا مرفوضًا مع الخطأ المحدد.
287287
288-
من بين هذه العناصر الخمسة ، يعد "Promise.all" الأكثر شيوعًا في الممارسة.
288+
من بين هذه العناصر الخمسة ، يعد "Promise.all" الأكثر شيوعًا في الممارسة.

0 commit comments

Comments
 (0)