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/09-classes/05-extend-natives/article.md
+23-22Lines changed: 23 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
2
-
# Extending built-in classes
2
+
# امتداد الـ `classes` المدمجة
3
3
4
-
Built-in classes like Array, Map and others are extendable also.
4
+
الـ `classes` المدمجة مثل الـ `Array` و `Map` وغيرهم قابلين للامتداد أيضا
5
5
6
-
For instance, here `PowerArray`inherits from the native `Array`:
6
+
على سبيل المثال ، هنا يرث `PowerArray`من`Array` الأصلي:
7
7
8
8
```js run
9
9
// add one more method to it (can do more)
@@ -21,20 +21,20 @@ alert(filteredArr); // 10, 50
21
21
alert(filteredArr.isEmpty()); // false
22
22
```
23
23
24
-
Please note a very interesting thing. Built-in methods like`filter`, `map`and others -- return new objects of exactly the inherited type `PowerArray`. Their internal implementation uses the object's `constructor` property for that.
24
+
يرجى ملاحظة شيء مثير جدا للاهتمام. الأساليب المدمجة مثل`filter` و`map`وغيرها - تُرجع كائنات جديدة من النوع الموروث`PowerArray` بالضبط. يستخدم التنفيذ الداخلي خاصية `مُنشئ 'الكائن لذلك.
25
25
26
-
In the example above,
26
+
في المثال أعلاه,
27
27
```js
28
28
arr.constructor=== PowerArray
29
29
```
30
30
31
-
When `arr.filter()`is called, it internally creates the new array of results using exactly `arr.constructor`, not basic `Array`. That's actually very cool, because we can keep using `PowerArray`methods further on the result.
31
+
عند استدعاء `arr.filter()`، فإنه ينشئ داخليًا مجموعة جديدة من النتائج باستخدام "arr.constructor" بالضبط ، وليس `Array` الأساسي. هذا في الواقع رائع جدًا ، لأنه يمكننا الاستمرار في استخدام طرق `` PowerArray` بشكل أكبر على النتيجة.
32
32
33
-
Even more, we can customize that behavior.
33
+
بل وأكثر من ذلك ، يمكننا تخصيص هذا السلوك.
34
34
35
-
We can add a special static getter `Symbol.species`to the class. If it exists, it should return the constructor that JavaScript will use internally to create new entities in `map`, `filter` and so on.
35
+
يمكننا إضافة مُصطلح ثابت خاص `Symbol.species`إلى الفصل. إذا كان موجودًا ، فيجب أن يُرجع المُنشئ الذي ستستخدمه JavaScript داخليًا لإنشاء كيانات جديدة في `خريطة` و` فلتر` وما إلى ذلك.
36
36
37
-
If we'd like built-in methods like `map` or `filter` to return regular arrays, we can return `Array` in `Symbol.species`, like here:
37
+
إذا كنا نرغب في استخدام طرق مضمنة مثل `الخريطة` أو` الفلتر` لإرجاع المصفوفات العادية ، فيمكننا إرجاع `المصفوفة` في` الرمز المحدد '، كما يلي:
alert(filteredArr.isEmpty()); // Error: filteredArr.isEmpty is not a function
63
63
```
64
64
65
-
As you can see, now`.filter` returns `Array`. So the extended functionality is not passed any further.
65
+
كما ترى ، الآن يُرجع`.filter`` Array`. لذلك لم يتم تمرير الدالة الموروثة أكثر من ذلك.
66
66
67
-
```smart header="Other collections work similarly"
68
-
Other collections, such as `Map` and `Set`, work alike. They also use `Symbol.species`.
69
-
```
67
+
"``smart header =" مجموعات أخرى تعمل بنفس الطريقة "
68
+
تعمل مجموعات أخرى ، مثل `Map` و` Set` ، على حد سواء. كما أنهم يستخدمون `Symbol.species`.
69
+
``
70
+
71
+
## لا وجود للتوريث الثابت في كل المدمجات
70
72
71
-
## No static inheritance in built-ins
73
+
لها دوال ثابتة خاصة بها ، مثل `Object.keys` ،` Array.isArray` إلخ.
72
74
73
-
Built-in objects have their own static methods, for instance `Object.keys`, `Array.isArray` etc.
75
+
كما نعلم بالفعل ، تمتد الفصول الدراسية الأصلية لبعضها البعض. على سبيل المثال ، `Array` يمتد` Object`.
74
76
75
-
As we already know, native classes extend each other. For instance, `Array` extends `Object`.
77
+
عادة ، عندما تمد فئة واحدة أخرى ، يتم توريث كل من الأساليب الثابتة وغير الثابتة. تم شرح ذلك تمامًا في المقالة [] (info: static-properties-methods # statics-and-inheritance).
76
78
77
-
Normally, when one class extends another, both static and non-static methods are inherited. That was thoroughly explained in the article [](info:static-properties-methods#statics-and-inheritance).
79
+
لكن الفصول المدمجة استثناء. لا يرثون إحصائيات عن بعضهم البعض.
78
80
79
-
But built-in classes are an exception. They don't inherit statics from each other.
81
+
على سبيل المثال ، يرث كل من `Array` و` Date` من `Object` ، لذا فإن نُسخهما تحتوي على طرق من` Object.prototype`. لكن `Array. [[Prototype]]` لا يشير إلى `Object` ، لذلك لا يوجد ، على سبيل المثال ،` Array.keys () `(أو` Date.keys () `) طريقة ثابتة.
80
82
81
-
For example, both `Array` and `Date`inherit from `Object`, so their instances have methods from `Object.prototype`. But `Array.[[Prototype]]` does not reference `Object`, so there's no, for instance, `Array.keys()` (or `Date.keys()`) static method.
83
+
إليك بنية الصورة لـ `Date`و`Object`:
82
84
83
-
Here's the picture structure for `Date` and `Object`:
84
85
85
86

86
87
87
-
As you can see, there's no link between `Date` and `Object`. They are independent, only `Date.prototype`inherits from `Object.prototype`.
88
+
كما ترى ، لا يوجد رابط بين `التاريخ` و` الكائن`. إنهم مستقلون ، فقط يرث `Date.prototype`من`Object.prototype`.
88
89
89
-
That's an important difference of inheritance between built-in objects compared to what we get with `extends`.
90
+
هذا اختلاف مهم في الميراث بين الكائنات المضمنة مقارنة بما نحصل عليه مع `extends` ''.
0 commit comments