Skip to content

Commit 8e146e8

Browse files
committed
Translate a part of article
1 parent d87dc2d commit 8e146e8

1 file changed

Lines changed: 15 additions & 15 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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,37 @@
5959

6060
حالا در جاوااسکریپت یک قهوه‌ساز همراه با انواع ویژگی خواهیم ساخت. یک قهوه‌ساز جزئیات زیادی دارد، ما برای ساده بودن آن‌ها را مدل‌سازی نمی‌کنیم (اگرچه می‌توانستیم).
6161

62-
## Protecting "waterAmount"
62+
## ویژگی "waterAmount" محافظت‌شده
6363

64-
Let's make a simple coffee machine class first:
64+
بیایید یک کلاس ساده قهوه‌ساز ایجاد کنیم:
6565

6666
```js run
6767
class CoffeeMachine {
68-
waterAmount = 0; // the amount of water inside
68+
waterAmount = 0; // مقدار آب درون
6969

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

7575
}
7676

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

80-
// add water
80+
// اضافه کردن آب
8181
coffeeMachine.waterAmount = 200;
8282
```
8383

84-
Right now the properties `waterAmount` and `power` are public. We can easily get/set them from the outside to any value.
84+
حالا ویژگی‌های `waterAmount` و `power` عمومی هستند. می‌توانیم به راحتی از بیرون آن‌ها را دریافت کنیم یا مقداردهی کنیم.
8585

86-
Let's change `waterAmount` property to protected to have more control over it. For instance, we don't want anyone to set it below zero.
86+
بیایید برای داشتن کنترل بیشتر ویژگی `waterAmount` را به محافظت‌شده تغییر دهیم. برای مثال، ما نمی‌خواهیم کسی آن را کمتر از صفر تنظیم کند.
8787

88-
**Protected properties are usually prefixed with an underscore `_`.**
88+
**قبل از ویژگی‌های محافظت‌شده معمولا یک زیرخط (underscore) `_` می‌آید.**
8989

90-
That is not enforced on the language level, but there's a well-known convention between programmers that such properties and methods should not be accessed from the outside.
90+
این نوع در سطح زبان اجرایی نشده اما یک قرارداد شناخته‌شده بین برنامه‌نویسان وجود دارد که نباید از بیرون به چنین ویژگی‌ها و متدهایی دسترسی پیدا کرد.
9191

92-
So our property will be called `_waterAmount`:
92+
پس ویژگی ما `_waterAmount` خواهد بود:
9393

9494
```js run
9595
class CoffeeMachine {
@@ -112,14 +112,14 @@ class CoffeeMachine {
112112

113113
}
114114

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

118-
// add water
119-
coffeeMachine.waterAmount = -10; // _waterAmount will become 0, not -10
118+
// اضافه کردن آب
119+
coffeeMachine.waterAmount = -10; // -برابر با 0 خواهد بود نه 10 _waterAmount
120120
```
121121

122-
Now the access is under control, so setting the water amount below zero becomes impossible.
122+
حالا دسترسی تحت کنترل است پس تنظیم مقدار آب کمتر از صفر ممکن نیست.
123123

124124
## Read-only "power"
125125

0 commit comments

Comments
 (0)