Skip to content

Commit 165c8cb

Browse files
committed
Translate a part of article
Line 19 needs more attention.
1 parent fcefb3a commit 165c8cb

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

1-js/09-classes/07-mixins/article.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
به عبارتی دیگر، یک *mixin* متدهایی که یک کار مشخص انجام می‌دهند را فراهم می‌کند اما از آن به تنهایی استفاده نمی‌کنیم بلکه از آن برای اضافه کردن همان کار مشخص به کلاس‌های دیگر استفاده می‌کنیم.
1414

15-
## A mixin example
15+
## یک مثال mixin
1616

17-
The simplest way to implement a mixin in JavaScript is to make an object with useful methods, so that we can easily merge them into a prototype of any class.
17+
ساده‌ترین راه برای پیاده‌سازی یک mixin در جاوااسکریپت ایجاد شیءای شامل متدهایی مفید است تا بتوانیم به راحتی آن‌ها را درون پروتوتایپ هر کلاسی ادغام کنیم.
1818

19-
For instance here the mixin `sayHiMixin` is used to add some "speech" for `User`:
19+
برای مثال اینجا `sayHiMixin` برای اضافه کردن «گفتار» به `User` استفاده شده است:
2020

2121
```js run
2222
*!*
@@ -32,22 +32,22 @@ let sayHiMixin = {
3232
};
3333

3434
*!*
35-
// usage:
35+
// :کاربرد
3636
*/!*
3737
class User {
3838
constructor(name) {
3939
this.name = name;
4040
}
4141
}
4242

43-
// copy the methods
43+
// کپی کردن متدها
4444
Object.assign(User.prototype, sayHiMixin);
4545

46-
// now User can say hi
46+
// بگوید (hi) می‌تواند سلام User حالا
4747
new User("Dude").sayHi(); // Hello Dude!
4848
```
4949

50-
There's no inheritance, but a simple method copying. So `User` may inherit from another class and also include the mixin to "mix-in" the additional methods, like this:
50+
ارث‌بری در کار نیست، فقط یک کپی کردن متد ساده است. پس `User` می‌تواند از کلاس دیگری ارث‌بری کند و همچنین mixin را هم شامل شود تا متدهای اضافی را «ترکیب» کند، مثل این:
5151

5252
```js
5353
class User extends Person {
@@ -57,9 +57,9 @@ class User extends Person {
5757
Object.assign(User.prototype, sayHiMixin);
5858
```
5959

60-
Mixins can make use of inheritance inside themselves.
60+
mixinها می‌توانند درون خود از ارث‌بری استفاده کنند.
6161

62-
For instance, here `sayHiMixin` inherits from `sayMixin`:
62+
برای مثال، اینجا `sayHiMixin` از `sayMixin` ارث‌بری می‌کند:
6363

6464
```js run
6565
let sayMixin = {
@@ -69,11 +69,11 @@ let sayMixin = {
6969
};
7070

7171
let sayHiMixin = {
72-
__proto__: sayMixin, // (or we could use Object.setPrototypeOf to set the prototype here)
72+
__proto__: sayMixin, // (برای تنظیم پروتوتایپ استفاده کنیم `Object.setPrototypeOf` یا می‌توانستیم اینجا از)
7373

7474
sayHi() {
7575
*!*
76-
// call parent method
76+
// فراخوانی متد والد
7777
*/!*
7878
super.say(`Hello ${this.name}`); // (*)
7979
},
@@ -88,22 +88,22 @@ class User {
8888
}
8989
}
9090

91-
// copy the methods
91+
// کپی کردن متدها
9292
Object.assign(User.prototype, sayHiMixin);
9393

94-
// now User can say hi
94+
// بگوید (hi) می‌تواند سلام User حالا
9595
new User("Dude").sayHi(); // Hello Dude!
9696
```
9797

98-
Please note that the call to the parent method `super.say()` from `sayHiMixin` (at lines labelled with `(*)`) looks for the method in the prototype of that mixin, not the class.
98+
لطفا توجه کنید که فراخوانی متد `super.say()` از `sayHiMixin` (در خطی که با `(*)` برچسب‌گذاری شده) در پروتوتایپ mixin به دنبال متد می‌گردد نه کلاس.
9999

100-
Here's the diagram (see the right part):
100+
اینجا شکل آن را داریم (قسمت راست را ببینید):
101101

102102
![](mixin-inheritance.svg)
103103

104-
That's because methods `sayHi` and `sayBye` were initially created in `sayHiMixin`. So even though they got copied, their `[[HomeObject]]` internal property references `sayHiMixin`, as shown in the picture above.
104+
دلیلش این است که `sayHi` و `sayBye` از اول درون `sayHiMixin` ایجاد شده‌اند. پس حتی با اینکه کپی شدند، ویژگی درونی `[[HomeObject]]` آن‌ها به `sayHiMixin` رجوع می‌کند، همانطور که در تصویر بالا نشان داده شده است.
105105

106-
As `super` looks for parent methods in `[[HomeObject]].[[Prototype]]`, that means it searches `sayHiMixin.[[Prototype]]`, not `User.[[Prototype]]`.
106+
چون `super` درون `[[HomeObject]].[[Prototype]]` به دنبال متدهای والد می‌گردد، یعنی `sayHiMixin.[[Prototype]]` را جست‌وجو می‌کند نه `User.[[Prototype]]` را.
107107

108108
## EventMixin
109109

0 commit comments

Comments
 (0)