You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/03-closure/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -183,7 +183,7 @@ Rectangles on the right-hand side demonstrate how the global Lexical Environment
183
183
184
184
1. When the script starts, the Lexical Environment is pre-populated with all declared variables.
185
185
- 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.
187
187
3.`phrase` is assigned a value.
188
188
4.`phrase` changes the value.
189
189
@@ -286,7 +286,7 @@ Later, when `counter()` is called, a new Lexical Environment is created for the
286
286
287
287

288
288
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.
290
290
291
291
**A variable is updated in the Lexical Environment where it lives.**
في هذا الرمز ، يأخذ `promises.map` قيم الإدخال ، ويحولها إلى وعود (فقط في حالة تمرير عدم الوعد) مع` p => Promise.resolve (p) `، ثم يضيف معالج` .then` إلى كل واحد.
195
195
196
+
<<<<<<< HEAD
196
197
يحول هذا المعالج نتيجة "القيمة" الناجحة إلى "{state:" الوفاء "و value}` والخطأ "reason" إلى "{state: "رفض"، reason} `. هذا هو بالضبط تنسيق `Promise.allSettled`.
198
+
=======
199
+
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`.
200
+
>>>>>>> e4e6a50b5762dd5dc4c0f0c58f870c64be39dcfa
197
201
198
202
الآن يمكننا استخدام "Promise.allSettled" للحصول على نتائج * جميع * الوعود المعطاة ، حتى لو رفض بعضها.
199
203
@@ -277,12 +281,22 @@ let promise = new Promise((resolve, reject) => reject(error));
277
281
278
282
هناك 5 طرق ثابتة لفئة `Promise`:
279
283
284
+
<<<<<<< HEAD
280
285
1. "Promise.all (الوعود)" - تنتظر جميع الوعود لحل وإرجاع مجموعة من نتائجها. إذا تم رفض أي من الوعود المعطاة ، يصبح خطأ "Promise.all" ، ويتم تجاهل جميع النتائج الأخرى.
281
286
2. "Promise.allSettled (الوعود)" (الطريقة المضافة حديثًا) - تنتظر جميع الوعود بتسوية نتائجها وإعادتها كمجموعة من الأشياء مع:
4. "Promise.resolve (القيمة)" - يقدم وعدًا ثابتًا بقيمة معينة.
286
291
5. "Promise.reject (خطأ)" - يقدم وعدًا مرفوضًا مع الخطأ المحدد.
292
+
=======
293
+
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.
294
+
2. `Promise.allSettled(promises)` (recently added method) -- waits for all promises to settle and returns their results as an array of objects with:
295
+
- `status`: `"fulfilled"` or `"rejected"`
296
+
- `value` (if fulfilled) or `reason` (if rejected).
297
+
3. `Promise.race(promises)` -- waits for the first promise to settle, and its result/error becomes the outcome.
298
+
4. `Promise.resolve(value)` -- makes a resolved promise with the given value.
299
+
5. `Promise.reject(error)` -- makes a rejected promise with the given error.
300
+
>>>>>>> e4e6a50b5762dd5dc4c0f0c58f870c64be39dcfa
287
301
288
302
من بين هذه العناصر الخمسة ، يعد "Promise.all" الأكثر شيوعًا في الممارسة.
0 commit comments