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/02-class-inheritance/article.md
-16Lines changed: 0 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -317,21 +317,13 @@ new Rabbit(); // animal
317
317
*/!*
318
318
```
319
319
320
-
<<<<<<< HEAD
321
320
اینجا، کلاس `Rabbit` کلاس `Animal` را تعمیم میدهد و فیلد `name` را با مقدار خودش بازنویسی میکند.
322
-
=======
323
-
Here, class `Rabbit` extends `Animal` and overrides the `name` field with its own value.
324
-
>>>>>>> 8d04d0d2db97276dbb2b451c30a7bd3e05d65831
325
321
326
322
هیچ سازندهای درون `Rabbit` وجود ندارد، پس سازده `Animal` فراخوانی میشود.
327
323
328
324
موضوع جالب این است که در هر دو مورد: `new Animal()` و `new Rabbit()`، تابع `alert` در خط `(*)` مقدار `animal` را نشان میدهد.
329
325
330
-
<<<<<<< HEAD
331
326
**به عبارتی دیگر، سازنده والد همیشه از مقدار فیلد خودش استفاده میکند، نه فیلد بازنویسی شده.**
332
-
=======
333
-
**In other words, the parent constructor always uses its own field value, not the overridden one.**
334
-
>>>>>>> 8d04d0d2db97276dbb2b451c30a7bd3e05d65831
335
327
336
328
چه چیزی درباره این عجیب است؟
337
329
@@ -368,19 +360,11 @@ new Rabbit(); // rabbit
368
360
369
361
...اما برای فیلدهای کلاس اینگونه نیست. همانطور که گفته شد، سازنده والد همیشه از فیلد والد استفاده میکند.
370
362
371
-
<<<<<<< HEAD
372
363
چرا تفاوت وجود دارد؟
373
364
374
365
خب دلیل آن درون ترتیب مقداردهی اولیه به فیلدها است. فیلد کلاس اینگونه مقداردهی اولیه میشود:
375
366
- قبل از سازنده برای کلاس پایه (که چیزی را تعمیم نمیدهد)،
376
367
- بلافاصله بعد از `super()` برای کلاس مشتق شده.
377
-
=======
378
-
Why is there a difference?
379
-
380
-
Well, the reason is the field initialization order. The class field is initialized:
381
-
- Before constructor for the base class (that doesn't extend anything),
382
-
- Immediately after `super()` for the derived class.
383
-
>>>>>>> 8d04d0d2db97276dbb2b451c30a7bd3e05d65831
384
368
385
369
در این مورد ما، `Rabbit` کلاس مشتق شده است. تابع `constructor()` درون آن وجود ندارد. همانطور که قبلا هم گفته شد، درست مانند این است که یک سازنده خالی فقط حاوی `super(...args)` وجود داشته باشد.
0 commit comments