Skip to content

Commit b714660

Browse files
authored
Merge pull request #173 from mahdiHashemi14/master
Translate tasks of Prototypal Inheritance
2 parents 7af2b5a + 8ecce28 commit b714660

8 files changed

Lines changed: 53 additions & 53 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
1. `true`, taken from `rabbit`.
3-
2. `null`, taken from `animal`.
4-
3. `undefined`, there's no such property any more.
2+
1. مقدار `true`، از `rabbit` گرفته شده.
3+
2. مقدار `null`، از `animal` گرفته شده.
4+
3. مقدار `undefined`، چنین ویژگی‌ای دیگر وجود ندارد.

1-js/08-prototypes/01-prototype-inheritance/1-property-after-delete/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Working with prototype
5+
# کار کردن با پروتوتایپ
66

7-
Here's the code that creates a pair of objects, then modifies them.
7+
اینجا کدی داریم که یک جفت از شیءها را ایجاد می‌کند و سپس آن‌ها را تغییر می‌دهد.
88

9-
Which values are shown in the process?
9+
کدام مقدار در فرایند نمایش داده می‌شود؟
1010

1111
```js
1212
let animal = {
@@ -28,4 +28,4 @@ delete animal.jumps;
2828
alert( rabbit.jumps ); // ? (3)
2929
```
3030

31-
There should be 3 answers.
31+
باید 3 جواب وجود داشته باشد.

1-js/08-prototypes/01-prototype-inheritance/2-search-algorithm/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
1. Let's add `__proto__`:
2+
1. بیایید `__proto__` را اضافه کنیم:
33

44
```js run
55
let head = {
@@ -27,6 +27,6 @@
2727
alert( table.money ); // undefined
2828
```
2929

30-
2. In modern engines, performance-wise, there's no difference whether we take a property from an object or its prototype. They remember where the property was found and reuse it in the next request.
30+
2. در موتورهای مدرن، که از لحاظ عملکرد هوشمند هستند، تفاوتی بین اینکه ما ویژگی‌ای را از شیء یا پروتوتایپ آن دریافت کنیم وجود ندارد. آن‌ها جایی که ویژگی پیدا شد را به خاطر می‌سپارند و در درخواست بعدی از آن استفاده می‌کنند.
3131

32-
For instance, for `pockets.glasses` they remember where they found `glasses` (in `head`), and next time will search right there. They are also smart enough to update internal caches if something changes, so that optimization is safe.
32+
برای مثال، برای `pockets.glasses` آن‌ها جایی که `glasses` را پیدا کردند (درون `head`) را به خاطر می‌سپارند و دفعه بعدی دقیقا همانجا را جست و جو می‌کند. همچنین آن‌ها به اندازه‌ای هوشمند هستند که اگر چیزی تغییر کند، کش‌های داخلی را بروزرسانی کنند تا بهینه‌سازی ایمن باشد.

1-js/08-prototypes/01-prototype-inheritance/2-search-algorithm/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Searching algorithm
5+
# الگوریتم جست و جو
66

7-
The task has two parts.
7+
این تمرین دو بخش دارد.
88

9-
Given the following objects:
9+
شیءهای زیر داده شده‌اند:
1010

1111
```js
1212
let head = {
@@ -27,5 +27,5 @@ let pockets = {
2727
};
2828
```
2929

30-
1. Use `__proto__` to assign prototypes in a way that any property lookup will follow the path: `pockets` -> `bed` -> `table` -> `head`. For instance, `pockets.pen` should be `3` (found in `table`), and `bed.glasses` should be `1` (found in `head`).
31-
2. Answer the question: is it faster to get `glasses` as `pockets.glasses` or `head.glasses`? Benchmark if needed.
30+
1. از `__proto__` برای مقداردهی پروتوتایپ‌ها استفاده کنید به طوری که جست و جوی هر ویژگی این مسیر را دنبال کند: `pockets` -> `bed` -> `table` -> `head`. برای مثال، `pockets.pen` باید `3` باشد (در `table` پیدا شد) و `bed.glasses` باید `1` باشد (در `head` پیدا شد).
31+
2. این سوال را جواب دهید: دریافت `glasses` به صورت `pockets.glasses` سریع‌تر است یا `head.glasses`؟ اگر نیاز بود بنچمارک انجام دهید.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
**The answer: `rabbit`.**
1+
**جواب: `rabbit`.**
22

3-
That's because `this` is an object before the dot, so `rabbit.eat()` modifies `rabbit`.
3+
به این دلیل که `this` برابر با شیء قبل از نقطه است پس `rabbit.eat()` شیء `rabbit` را تغییر می‌دهد.
44

5-
Property lookup and execution are two different things.
5+
جست و جوی ویژگی و اجرا کردن دو موضوع جدا هستند.
66

7-
The method `rabbit.eat` is first found in the prototype, then executed with `this=rabbit`.
7+
متد `rabbit.eat` ابتدا در پروتوتایپ پیدا شد سپس با `this=rabbit` اجرا شد.

1-js/08-prototypes/01-prototype-inheritance/3-proto-and-this/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Where does it write?
5+
# کجا می‌نویسد؟
66

7-
We have `rabbit` inheriting from `animal`.
7+
ما `rabbit` را داریم که از `animal` ارث‌بری می‌کند.
88

9-
If we call `rabbit.eat()`, which object receives the `full` property: `animal` or `rabbit`?
9+
اگر ما `rabbit.eat()` را فراخوانی کنیم، کدام شیء ویژگی `full` را دریافت می‌کند: `animal` یا `rabbit`؟
1010

1111
```js
1212
let animal = {

1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
Let's look carefully at what's going on in the call `speedy.eat("apple")`.
1+
بیایید با دقت نگاه کنیم که در فراخوانی `speedy.eat("سیب")` چه اتفاقی می‌افتد.
22

3-
1. The method `speedy.eat` is found in the prototype (`=hamster`), then executed with `this=speedy` (the object before the dot).
3+
1. متد `speedy.eat` درون پروتوتایپ (`=hamster`) پیدا شده، سپس با `this=speedy` اجرا می‌شود (شیء قبل از نقطه).
44

5-
2. Then `this.stomach.push()` needs to find `stomach` property and call `push` on it. It looks for `stomach` in `this` (`=speedy`), but nothing found.
5+
2. سپس `this.stomach.push()` باید ویژگی `stomach` را پیدا کند و `push` را روی آن فراخوانی کند. به نظر می‌رسد این متد درون `this` (`=speedy`) به دنبال `stomach` می‌گردد، اما چیزی پیدا نشد.
66

7-
3. Then it follows the prototype chain and finds `stomach` in `hamster`.
7+
3. سپس زنجیره پروتوتایپ را دنبال می‌کند و `stomach` را درون `hamster` پیدا می‌کند.
88

9-
4. Then it calls `push` on it, adding the food into *the stomach of the prototype*.
9+
4. سپس `push` را روی آن فراخوانی می‌کند، که غذا را به *stomach درون پروتوتایپ* اضافه می‌کند.
1010

11-
So all hamsters share a single stomach!
11+
پس تمام همسترها شکم (stomach) یکسانی را به اشتراک می‌گذارند!
1212

13-
Both for `lazy.stomach.push(...)` and `speedy.stomach.push()`, the property `stomach` is found in the prototype (as it's not in the object itself), then the new data is pushed into it.
13+
هم برای `lazy.stomach.push(...)` و `speedy.stomach.push()`، ویژگی `stomach` درون پروتوتایپ پیدا شده است (چون درون خود شیء وجود ندارد)، سپس داده جدید به داخل آن فرستاده می‌شود.
1414

15-
Please note that such thing doesn't happen in case of a simple assignment `this.stomach=`:
15+
لطفا توجه کنید که در صورت وجود یک مقداردهی ساده `this.stomach=` چنین چیزی اتفاق نمی‌افتد:
1616

1717
```js run
1818
let hamster = {
1919
stomach: [],
2020

2121
eat(food) {
2222
*!*
23-
// assign to this.stomach instead of this.stomach.push
23+
// this.stomach.push به جای this.stomach برابر قرار دادن با
2424
this.stomach = [food];
2525
*/!*
2626
}
@@ -34,17 +34,17 @@ let lazy = {
3434
__proto__: hamster
3535
};
3636

37-
// Speedy one found the food
38-
speedy.eat("apple");
39-
alert( speedy.stomach ); // apple
37+
// غذا را پیدا کرد Speedy همستر
38+
speedy.eat("سیب");
39+
alert( speedy.stomach ); // سیب
4040

41-
// Lazy one's stomach is empty
42-
alert( lazy.stomach ); // <nothing>
41+
// خالی است Lazy شکم همستر
42+
alert( lazy.stomach ); // <هیچی>
4343
```
4444

45-
Now all works fine, because `this.stomach=` does not perform a lookup of `stomach`. The value is written directly into `this` object.
45+
حالا همه چیز به درستی کار می‌کند، چون `this.stomach=` در جست و جوی `stomach` نیست. مقدار به صورت مستقیم درون شیء `this` نوشته می‌شود.
4646

47-
Also we can totally avoid the problem by making sure that each hamster has their own stomach:
47+
همچنین می‌توانیم با اطمینان از اینکه هر همستر stomach خودش را دارا می‌باشد از این مشکل جلوگیری کنیم:
4848

4949
```js run
5050
let hamster = {
@@ -69,12 +69,12 @@ let lazy = {
6969
*/!*
7070
};
7171

72-
// Speedy one found the food
73-
speedy.eat("apple");
74-
alert( speedy.stomach ); // apple
72+
// غذا را پیدا کرد Speedy همستر
73+
speedy.eat("سیب");
74+
alert( speedy.stomach ); // سیب
7575

76-
// Lazy one's stomach is empty
77-
alert( lazy.stomach ); // <nothing>
76+
// خالی است Lazy شکم همستر
77+
alert( lazy.stomach ); // <هیچی>
7878
```
7979

80-
As a common solution, all properties that describe the state of a particular object, like `stomach` above, should be written into that object. That prevents such problems.
80+
به عنوان یک راه‌حل عام، تمام ویژگی‌هایی که وضعیت یک شیء خاص را توصیف می‌کنند، مانند `stomach` بالا، باید درون همان شیء نوشته شوند. این کار از بروز مشکلات جلوگیری می‌کند.

1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Why are both hamsters full?
5+
# چرا هر دو دو همستر سیر هستند؟
6+
7+
ما دو همستر داریم: `speedy` و `lazy` که از شیء عمومی `hamster` ارث‌بری می‌کنند.
68

7-
We have two hamsters: `speedy` and `lazy` inheriting from the general `hamster` object.
8-
9-
When we feed one of them, the other one is also full. Why? How can we fix it?
9+
زمانی که ما به یکی از آن‌ها غذا می‌دهیم، دیگری هم سیر می‌شود. چرا؟ چگونه می‌توانیم این مشکل را رفع کنیم؟
1010

1111
```js run
1212
let hamster = {
@@ -25,11 +25,11 @@ let lazy = {
2525
__proto__: hamster
2626
};
2727

28-
// This one found the food
29-
speedy.eat("apple");
30-
alert( speedy.stomach ); // apple
28+
// این همستر غذا را پیدا کرد
29+
speedy.eat("سیب");
30+
alert( speedy.stomach ); // سیب
3131

32-
// This one also has it, why? fix please.
33-
alert( lazy.stomach ); // apple
32+
// این همستر هم غذا را دارد، چرا؟ لطفا این را درست کنید.
33+
alert( lazy.stomach ); // سیب
3434
```
3535

0 commit comments

Comments
 (0)