Skip to content

Commit 47109d5

Browse files
committed
Class inheritance
1 parent d3cf00f commit 47109d5

6 files changed

Lines changed: 145 additions & 142 deletions

File tree

1-js/09-classes/02-class-inheritance/1-class-constructor-error/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
That's because the child constructor must call `super()`.
1+
هذا لأنه يجب على منشئ الطفل استدعاء `` super () `.
22

3-
Here's the corrected code:
3+
إليك الكود المصحح:
44

55
```js run
66
class Animal {

1-js/09-classes/02-class-inheritance/1-class-constructor-error/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 5
1+
درجة الأهمية : 5
22

33
---
44

5-
# Error creating an instance
5+
# خطأ في إنشاء مثيل
66

7-
Here's the code with `Rabbit` extending `Animal`.
7+
إليك الرمز الذي يحتوي على "أرنب" يمتد "حيوان".
88

9-
Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it.
9+
لسوء الحظ ، لا يمكن إنشاء كائنات "أرنب". ماالخطب؟ اصلحه.
1010
```js run
1111
class Animal {
1212

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
importance: 5
1+
درجة الأهمية: 5
22

33
---
44

5-
# Extended clock
5+
# ساعة ممتدة
66

7-
We've got a `Clock` class. As of now, it prints the time every second.
7+
لدينا فصل "ساعة". حتى الآن ، يطبع الوقت كل ثانية.
88

99

10-
[js src="source.view/clock.js"]
10+
[js src = "source.view / clock.js"]
1111

12-
Create a new class `ExtendedClock` that inherits from `Clock` and adds the parameter `precision` -- the number of `ms` between "ticks". Should be `1000` (1 second) by default.
12+
أنشئ فئة جديدة `ExtendedClock` ترث من` Clock` وتضيف المعلمة `الدقة` - عدد` ms` بين "القراد". يجب أن يكون "1000" (ثانية واحدة) افتراضيًا.
1313

14-
- Your code should be in the file `extended-clock.js`
15-
- Don't modify the original `clock.js`. Extend it.
14+
- يجب أن يكون الكود الخاص بك في ملف `ممتد على مدار الساعة. js`
15+
- لا تعدّل "clock.js" الأصلي. توسيعها.

1-js/09-classes/02-class-inheritance/3-class-extend-object/solution.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
First, let's see why the latter code doesn't work.
1+
أولاً ، دعنا نرى لماذا لا يعمل الكود الأخير.
22

3-
The reason becomes obvious if we try to run it. An inheriting class constructor must call `super()`. Otherwise `"this"` won't be "defined".
3+
يصبح السبب واضحًا إذا حاولنا تشغيله. يجب على مُنشئ الفصل الموروث استدعاء `` super () `. وإلا فلن يتم تحديد "هذا" ".
44

5-
So here's the fix:
5+
إذن هذا هو الإصلاح:
66

77
```js run
88
class Rabbit extends Object {
@@ -19,16 +19,16 @@ let rabbit = new Rabbit("Rab");
1919
alert( rabbit.hasOwnProperty('name') ); // true
2020
```
2121

22-
But that's not all yet.
22+
لكن هذا ليس كل شيء بعد.
2323

24-
Even after the fix, there's still important difference in `"class Rabbit extends Object"` versus `class Rabbit`.
24+
حتى بعد الإصلاح ، لا يزال هناك اختلاف مهم في "class rabbit يوسع الكائن" "مقابل" class Rabbit ".
2525

26-
As we know, the "extends" syntax sets up two prototypes:
26+
كما نعلم ، فإن الصيغة "الممتدة" تضع نموذجين أوليين:
2727

28-
1. Between `"prototype"` of the constructor functions (for methods).
29-
2. Between the constructor functions themselves (for static methods).
28+
1. بين "النموذج" لوظائف المنشئ (للطرق).
29+
2. بين وظائف المنشئ أنفسهم (للأساليب الثابتة).
3030

31-
In our case, for `class Rabbit extends Object` it means:
31+
في حالتنا ، تعني كلمة "أرنب يمتد الكائن" ما يلي:
3232

3333
```js run
3434
class Rabbit extends Object {}
@@ -37,7 +37,7 @@ alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1) true
3737
alert( Rabbit.__proto__ === Object ); // (2) true
3838
```
3939

40-
So `Rabbit` now provides access to static methods of `Object` via `Rabbit`, like this:
40+
إذن يوفر "الأرنب" الآن إمكانية الوصول إلى الأساليب الثابتة لـ "الكائن" عبر "الأرنب" ، على النحو التالي:
4141

4242
```js run
4343
class Rabbit extends Object {}
@@ -48,9 +48,9 @@ alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // a,b
4848
*/!*
4949
```
5050

51-
But if we don't have `extends Object`, then `Rabbit.__proto__` is not set to `Object`.
51+
ولكن إذا لم يكن لدينا `Extended Object` ، فلن يتم تعيين` Rabbit .__ proto__` على `Object`.
5252

53-
Here's the demo:
53+
هنا هو العرض التوضيحي:
5454

5555
```js run
5656
class Rabbit {}
@@ -65,15 +65,15 @@ alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // Error
6565
*/!*
6666
```
6767

68-
So `Rabbit` doesn't provide access to static methods of `Object` in that case.
68+
لذا `Rabbit` لا يوفر الوصول إلى الأساليب الثابتة لـ "الكائن" في هذه الحالة.
6969

70-
By the way, `Function.prototype` has "generic" function methods, like `call`, `bind` etc. They are ultimately available in both cases, because for the built-in `Object` constructor, `Object.__proto__ === Function.prototype`.
70+
بالمناسبة ، يحتوي `Function.prototype` على طرق وظيفية" عامة "، مثل` call` و` bind` وما إلى ذلك. وهي متاحة في النهاية في كلتا الحالتين ، لأن مُنشئ `Object` المدمج ،` Object .__ proto__ = == Function.prototype`.
7171

72-
Here's the picture:
72+
ها هي الصورة:
7373

7474
![](rabbit-extends-object.svg)
7575

76-
So, to put it short, there are two differences:
76+
لذلك ، باختصار ، هناك اختلافان:
7777

7878
| class Rabbit | class Rabbit extends Object |
7979
|--------------|------------------------------|

1-js/09-classes/02-class-inheritance/3-class-extend-object/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 3
1+
درجة الأهمية: 3
22

33
---
44

5-
# Class extends Object?
5+
# فئة تمدد الكائن؟
66

7-
As we know, all objects normally inherit from `Object.prototype` and get access to "generic" object methods like `hasOwnProperty` etc.
7+
كما نعلم ، عادة ما ترث جميع الكائنات من `Object.prototype` وتحصل على طرق للكائنات" العامة "مثل` hasOwnProperty` وما إلى ذلك.
88

9-
For instance:
9+
على سبيل المثال:
1010

1111
```js run
1212
class Rabbit {
@@ -23,11 +23,11 @@ alert( rabbit.hasOwnProperty('name') ); // true
2323
*/!*
2424
```
2525

26-
But if we spell it out explicitly like `"class Rabbit extends Object"`, then the result would be different from a simple `"class Rabbit"`?
26+
ولكن إذا وضحناها صراحة مثل "class class rabbit Extended Object" ، فستكون النتيجة مختلفة عن "class rabbit" بسيطة؟
2727

28-
What's the difference?
28+
ماهو الفرق؟
2929

30-
Here's an example of such code (it doesn't work -- why? fix it?):
30+
فيما يلي مثال لمثل هذا الرمز (لا يعمل - لماذا؟ إصلاحه؟):
3131

3232
```js
3333
class Rabbit extends Object {

0 commit comments

Comments
 (0)