Skip to content

Class inheritance #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
That's because the child constructor must call `super()`.
دلیلش این است که تابع سازنده فرزند باید `super()` را فراخوانی کند.

Here's the corrected code:
اینجا کد درست را داریم:

```js run
class Animal {
Expand All @@ -21,7 +21,7 @@ class Rabbit extends Animal {
}

*!*
let rabbit = new Rabbit("White Rabbit"); // ok now
let rabbit = new Rabbit("خرگوش سفید"); // الان مشکلی نیست
*/!*
alert(rabbit.name); // White Rabbit
alert(rabbit.name); // خرگوش سفید
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Error creating an instance
# ارور در ساختن نمونه

Here's the code with `Rabbit` extending `Animal`.
اینجا کدی داریم که `Rabbit` کلاس `Animal` را تعمیم می‌دهد.

Unfortunately, `Rabbit` objects can't be created. What's wrong? Fix it.
متاسفانه، شیءهای `Rabbit` نمی‌توانند ساخته شوند. چه چیزی اشتباه است؟ آن را درست کنید.
```js run
class Animal {

Expand All @@ -24,7 +24,7 @@ class Rabbit extends Animal {
}

*!*
let rabbit = new Rabbit("White Rabbit"); // Error: this is not defined
let rabbit = new Rabbit("خرگوش سفید"); // تعریف نشده است this :ارور
*/!*
alert(rabbit.name);
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
clock.start();


/* Your class should work like this: */
/* :کلاس شما باید اینگونه کار کند */

/*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 5

---

# Extended clock
# ساعت تعمیم داده شده

We've got a `Clock` class. As of now, it prints the time every second.
ما یک کلاس `Clock`(ساعت) داریم. هم اکنون، هر ثانیه را نمایش می‌دهد.


[js src="source.view/clock.js"]

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.
یک کلاس جدید `ExtendedClock` بسازید که از `Clock` ارث‌بری می‌کند و پارامتر `precision` -- تعداد `ms` بین هر «تیک تاک» -- را اضافه می‌کند. به طور پیش‌فرض باید `1000` (یک ثانیه) باشد.

- Your code should be in the file `extended-clock.js`
- Don't modify the original `clock.js`. Extend it.
- کد شما باید در فایل `extended-clock.js` باشد.
- فایل اصلی `clock.js` را تغییر ندهید. آن را گسترش دهید.
Loading