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
Here `Article.compare` stands "above" articles, as a means to compare them. It's not a method of an article, but rather of the whole class.
66
+
هنا "Article.compare" تقف المقالات "أعلاه" ، كوسيلة لمقارنتها. إنها ليست دالة لـ `article` ، ولكن بدلاً من الـ `class` بأكمله.
67
67
68
-
Another example would be a so-called "factory" method. Imagine, we need few ways to create an article:
68
+
مثال آخر هو ما يسمى طريقة "المصنع". تخيل ، نحن بحاجة إلى طرق قليلة لإنشاء مقال:
69
69
70
-
1.Create by given parameters (`title`, `date` etc).
71
-
2.Create an empty article with today's date.
72
-
3. ...or else somehow.
70
+
1.إنشاء بواسطة معلمات معينة (`العنوان` ،` التاريخ` وما إلى ذلك).
71
+
2.إنشاء مقال فارغ بتاريخ اليوم.
72
+
3. ... أو بطريقة أخرى.
73
73
74
-
The first way can be implemented by the constructor. And for the second one we can make a static method of the class.
74
+
يمكن تنفيذ الطريقة الأولى من قبل المنشئ. وللثاني يمكننا عمل طريقة ثابتة للفئة.
75
75
76
-
Like`Article.createTodays()`here:
76
+
مثل`Article.createTodays()`هنا:
77
77
78
78
```js run
79
79
classArticle {
@@ -95,9 +95,9 @@ let article = Article.createTodays();
95
95
alert( article.title ); // Today's digest
96
96
```
97
97
98
-
Now every time we need to create a today's digest, we can call `Article.createTodays()`. Once again, that's not a method of an article, but a method of the whole class.
98
+
الآن في كل مرة نحتاج فيها إلى إنشاء ملخص اليوم ، يمكننا استدعاء `` Article.createTodays () `. مرة أخرى ، هذه ليست طريقة لمقالة ، ولكنها طريقة للفصل بأكمله.
99
99
100
-
Static methods are also used in database-related classes to search/save/remove entries from the database, like this:
100
+
يتم استخدام الأساليب الثابتة أيضًا في الفئات المتعلقة بقاعدة البيانات للبحث / حفظ / إزالة الإدخالات من قاعدة البيانات ، مثل هذا:
101
101
102
102
```js
103
103
// assuming Article is a special class for managing articles
@@ -109,7 +109,7 @@ Article.remove({id: 12345});
109
109
110
110
[recent browser=Chrome]
111
111
112
-
Static properties are also possible, they look like regular class properties, but prepended by`static`:
112
+
الخصائص الثابتة ممكنة أيضًا ، فهي تبدو مثل خصائص الفئة العادية ، ولكن يتم إلحاقها بـ`static`:
113
113
114
114
```js run
115
115
classArticle {
@@ -125,11 +125,11 @@ That is the same as a direct assignment to `Article`:
125
125
Article.publisher="Ilya Kantor";
126
126
```
127
127
128
-
## Inheritance of static properties and methods
128
+
## وراثة الدوال والخصائص الثابتة
129
129
130
-
Static properties and methods are inherited.
130
+
الخصائص والأساليب الثابتة موروثة.
131
131
132
-
For instance, `Animal.compare`and `Animal.planet`in the code below are inherited and accessible as `Rabbit.compare`and `Rabbit.planet`:
132
+
على سبيل المثال ، `Animal.compare`و`Animal.planet`في الشفرة أدناه موروثة ويمكن الوصول إليها باسم `Rabbit.compare`و`Rabbit.planet`:
133
133
134
134
```js run
135
135
classAnimal {
@@ -174,9 +174,9 @@ rabbits[0].run(); // Black Rabbit runs with speed 5.
174
174
alert(Rabbit.planet); // Earth
175
175
```
176
176
177
-
Now when we call `Rabbit.compare`, the inherited `Animal.compare` will be called.
177
+
الآن عندما نسمي "Rabbit.compare" ، سيتم استدعاء "Animal.compare" الموروث.
178
178
179
-
How does it work? Again, using prototypes. As you might have already guessed, `extends` gives `Rabbit` the `[[Prototype]]`reference to `Animal`.
179
+
كيف يعمل؟ مرة أخرى ، باستخدام النماذج الأولية. كما كنت قد خمنت بالفعل ، فإن كلمة "يمتد" تعطي كلمة "أرنب" يشير "[[نموذج أولي]]` إلى "حيوان".
Static methods are used for the functionality that belongs to the class "as a whole". It doesn't relate to a concrete class instance.
205
+
يتم استخدام الأساليب الثابتة للوظيفة التي تنتمي إلى الفئة "ككل". لا يتعلق الأمر بمثيل فئة ملموسة.
206
206
207
-
For example, a method for comparison`Article.compare(article1, article2)`or a factory method `Article.createTodays()`.
207
+
على سبيل المثال ، طريقة للمقارنة`Article.compare(article1 ، article2)`أو طريقة مصنع `Article.createTodays()`.
208
208
209
-
They are labeled by the word `static` in class declaration.
209
+
يتم تسميتها بكلمة "ثابت" في إعلان الفئة.
210
210
211
-
Static properties are used when we'd like to store class-level data, also not bound to an instance.
211
+
يتم استخدام الخصائص الثابتة عندما نرغب في تخزين البيانات على مستوى الفصل الدراسي ، والتي لا ترتبط أيضًا بمثيل.
212
+
213
+
الصيغة هي:
212
214
213
-
The syntax is:
214
215
215
216
```js
216
217
classMyClass {
@@ -222,13 +223,14 @@ class MyClass {
222
223
}
223
224
```
224
225
225
-
Technically, static declaration is the same as assigning to the class itself:
226
+
من الناحية الفنية ، فإن الإعلان الثابت هو نفسه التخصيص للـ `class` نفسها:
226
227
227
228
```js
228
229
MyClass.property=...
229
230
MyClass.method=...
230
231
```
231
232
232
-
Static properties and methods are inherited.
233
+
الخصائص والأساليب الثابتة موروثة.
234
+
235
+
بالنسبة إلى "الفئة B التي تمد A" ، يشير النموذج الأولي للفئة `B` نفسها إلى` A`: `B. [[Prototype]] = A`. لذا ، إذا لم يتم العثور على حقل في `B` ، فسيستمر البحث في` A`.
233
236
234
-
For `class B extends A` the prototype of the class `B` itself points to `A`: `B.[[Prototype]] = A`. So if a field is not found in `B`, the search continues in `A`.
0 commit comments