Skip to content

Commit 076ab8e

Browse files
committed
Translate a part of article
Line 128 needs more attention
1 parent 8e146e8 commit 076ab8e

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

  • 1-js/09-classes/04-private-protected-properties-methods

1-js/09-classes/04-private-protected-properties-methods/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CoffeeMachine {
6969

7070
constructor(power) {
7171
this.power = power;
72-
alert( `یک قهوه‌ساز ایجاد کردیم، قدرت: ${power}` );
72+
alert( `یک قهوه‌ساز ایجاد کردیم، توان: ${power}` );
7373
}
7474

7575
}
@@ -121,13 +121,13 @@ coffeeMachine.waterAmount = -10; // -برابر با 0 خواهد بود نه 10
121121

122122
حالا دسترسی تحت کنترل است پس تنظیم مقدار آب کمتر از صفر ممکن نیست.
123123

124-
## Read-only "power"
124+
## ویژگی "power" فقط‌خواندنی
125125

126-
For `power` property, let's make it read-only. It sometimes happens that a property must be set at creation time only, and then never modified.
126+
بیایید ویژگی `power` را فقط‌خواندنی کنیم. گاهی اوقات یک ویژگی باید فقط زمان ایجاد کردن مقداردهی شود و دیگر هیچ‌وقت تغییر نکند.
127127

128-
That's exactly the case for a coffee machine: power never changes.
128+
این دقیقا برای قهوه‌ساز هم صدق می‌کند: توان (power) هیچ‌وقت تغییر نمی‌کند.
129129

130-
To do so, we only need to make getter, but not the setter:
130+
برای انجام این کار، ما فقط نیاز داریم که یک getter ایجاد کنیم اما setter را نه:
131131

132132
```js run
133133
class CoffeeMachine {
@@ -143,18 +143,18 @@ class CoffeeMachine {
143143

144144
}
145145

146-
// create the coffee machine
146+
// ایجاد قهوه‌ساز
147147
let coffeeMachine = new CoffeeMachine(100);
148148

149-
alert(`Power is: ${coffeeMachine.power}W`); // Power is: 100W
149+
alert(`توان: ${coffeeMachine.power} وات`); // توان: 100 وات
150150

151-
coffeeMachine.power = 25; // Error (no setter)
151+
coffeeMachine.power = 25; // (نداریم setter) ارور
152152
```
153153

154-
````smart header="Getter/setter functions"
155-
Here we used getter/setter syntax.
154+
````smart header="تابع‌های Getter/setter"
155+
اینجا ما از سینتکس getter/setter استفاده کردیم.
156156
157-
But most of the time `get.../set...` functions are preferred, like this:
157+
اما اکثر اوقات تابع‌های `get.../set...` ترجیح داده می‌شوند، مثلا اینگونه:
158158
159159
```js
160160
class CoffeeMachine {
@@ -173,15 +173,15 @@ class CoffeeMachine {
173173
new CoffeeMachine().setWaterAmount(100);
174174
```
175175
176-
That looks a bit longer, but functions are more flexible. They can accept multiple arguments (even if we don't need them right now).
176+
این کمی طولانی‌تر بنظر می‌رسد اما تابع‌ها بیشتر منعطف هستند. آن‌ها می‌توانند چند آرگومان دریافت کنند (حتی اگر ما همین الان به آن‌ها نیاز نداشته باشیم).
177177
178-
On the other hand, get/set syntax is shorter, so ultimately there's no strict rule, it's up to you to decide.
178+
از سویی دیگر، سینتکس get/set` کوتاه‌تر است پس در نهایت هیچ قانونی وجود ندارد، تصمیم با شماست.
179179
````
180180

181-
```smart header="Protected fields are inherited"
182-
If we inherit `class MegaMachine extends CoffeeMachine`, then nothing prevents us from accessing `this._waterAmount` or `this._power` from the methods of the new class.
181+
```smart header="فیلدهای محافظت‌شده به ارث برده می‌شوند"
182+
اگر ما `class MegaMachine extends CoffeeMachine` را ارث‌بری کنیم، سپس چیزی جلوی ما را برای دسترسی به `this._waterAmount` یا `this._power` از متدهای کلاس جدید نمی‌گیرد.
183183
184-
So protected fields are naturally inheritable. Unlike private ones that we'll see below.
184+
پس فیلدهای محافظت‌شده به طور طبیعی قابل ارث‌بری هستند. برخلاف فیلدهای خصوصی که پایین خواهیم دید.
185185
```
186186

187187
## Private "#waterLimit"

0 commit comments

Comments
 (0)