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/04-object-basics/07-optional-chaining/article.md
+4-22Lines changed: 4 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,13 +40,8 @@ alert( user && user.address && user.address.street ); // يظهر لنا undefin
40
40
41
41
يؤدي التسلسل الاختياري `.?` إلى إيقاف تقييم الكود البرمجي وإرجاع `undefined` إذا كانت قيمة الجزء الموجود قبل (أيسر) التركيب `.?` هي `null` أو `undfined`.
42
42
43
-
<<<<<<< HEAD
44
43
وللإيجاز، سنقول ضمن هذه المقالة أن شيئاً ما "موجود" إذا لم تكن قيمته `null` ولم تكن `undefined` كذلك.
45
44
46
-
=======
47
-
**Further in this article, for brevity, we'll be saying that something "exists" if it's not `null` and not `undefined`.**
48
-
>>>>>>> c3a11c85e54153ebb137b5541b1d1f751c804439
49
-
50
45
وأما الطريقة الآمنة للوصول لـِ `user.address.street` هي:
يرجى ملاحظة أن التركيب أو الشقّ `.?` يعمل بشكل صحيح حيث يتم وضعه بالضبط، وليس بعد ذلك المكان الذي تم وضعه فيه.
69
63
70
-
في السطرين الأخيرين، سيتوقف تقييم الكود البرمجي بشكل فوري بعد الشقّ `.?user` ولا يستمر أبداً للخصائص التي تليه. ولكن إذا كان الغرض `user` موجوداً بالفعل، فيجب أن تكون الخصائص الوسيطة موجودة ونقصد بالخصائص الوسيطة `user.address` مثلاً.
71
-
=======
72
-
Please note: the `?.` syntax makes optional the value before it, but not any further.
64
+
في السطرين الأخيرين، سيتوقف تقييم الكود البرمجي بشكل فوري بعد الشقّ `.?user` ولا يستمر أبداً للخصائص التي تليه.
73
65
74
-
In the example above, `user?.` allows only `user` to be `null/undefined`.
66
+
يقوم التسلسل الاختياري فقط باختبار القيم `null/undefined`، ولا يتداخل مع ميكانيكية أي من اللغات الأخرى.
75
67
76
-
On the other hand, if `user` does exist, then it must have `user.address` property, otherwise `user?.address.street` gives an error at the second dot.
77
-
>>>>>>> c3a11c85e54153ebb137b5541b1d1f751c804439
68
+
ولكن إذا كان الغرض `user` موجوداً بالفعل، فيجب أن تكون الخصائص الوسيطة موجودة ونقصد بالخصائص الوسيطة `user.address` مثلاً.
78
69
79
70
```warn header="لا تفرط في استخدام تركيب التسلسل الاختياري"
80
71
يجب أن نستخدم التركيب `.?` فقط عندما يكون هناك غرض، كائن أو خاصية غير موجودة بالأصل.
@@ -84,23 +75,14 @@ On the other hand, if `user` does exist, then it must have `user.address` proper
84
75
وبالتالي، إذا كان غرض المستخدم `user` غير معرف بسبب خطأ ما، فسوف نعرف عن هذا الخطأ ونصلحه. وإلا ستتسبب هذه الطريقة بإسكات الأخطاء البرمجية وقد لا يكون ذلك مناسباً، بل سيصبح من الصعب تصحيح هذه الأخطاء وكشفها.
85
76
```
86
77
87
-
<<<<<<< HEAD
88
78
````warn header="المتحول الواقع قبل التركيب `.?` يجب أن يكون معرّفاً"
89
79
إذا لم يتمّ تعريف المتحول `user`، سيؤدي التعبير `user?.anything` إلى حصول خطأ:
90
-
=======
91
-
````warn header="The variable before `?.` must be declared"
92
-
If there's no variable `user` at all, then `user?.anything` triggers an error:
93
-
>>>>>>> c3a11c85e54153ebb137b5541b1d1f751c804439
94
80
95
81
```js run
96
82
// ReferenceError: user is not defined
97
83
user?.address;
98
84
```
99
-
<<<<<<< HEAD
100
-
يقوم التسلسل الاختياري فقط باختبار القيم `null/undefined`، ولا يتداخل مع ميكانيكية أي من اللغات الأخرى.
101
-
=======
102
-
There must be `let/const/varuser`. Theoptionalchainingworksonlyfordeclaredvariables.
0 commit comments