Skip to content

Commit 6d47e5f

Browse files
committed
Translate a part of article
1 parent 07d8631 commit 6d47e5f

1 file changed

Lines changed: 18 additions & 18 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: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ new CoffeeMachine().setWaterAmount(100);
188188

189189
[recent browser=none]
190190

191-
There's a finished JavaScript proposal, almost in the standard, that provides language-level support for private properties and methods.
191+
یک طرح پیشنهادی تمام شده جاوااسکریپت وجود دارد، تقریبا درون استاندارد وارد شده، که پشتیبانی برای ویژگی‌ها و متدهای خصوصی (private) را در سطح زبان فراهم می‌کند.
192192

193-
Privates should start with `#`. They are only accessible from inside the class.
193+
ویژگی‌ها خصوصی با `#` شروع می‌شوند. آن‌ها فقط از درون کلاس قابل دسترس هستند.
194194

195-
For instance, here's a private `#waterLimit` property and the water-checking private method `#fixWaterAmount`:
195+
برای مثال، اینجا ویژگی خصوصی `#waterLimit` و متد خصوصی `#fixWaterAmount` را داریم:
196196

197197
```js run
198198
class CoffeeMachine {
@@ -216,17 +216,17 @@ class CoffeeMachine {
216216
let coffeeMachine = new CoffeeMachine();
217217

218218
*!*
219-
// can't access privates from outside of the class
220-
coffeeMachine.#fixWaterAmount(123); // Error
221-
coffeeMachine.#waterLimit = 1000; // Error
219+
// نمی‌توان بیرون از کلاس به خصوصی‌ها دسترسی پیدا کرد
220+
coffeeMachine.#fixWaterAmount(123); // ارور
221+
coffeeMachine.#waterLimit = 1000; // ارور
222222
*/!*
223223
```
224224

225-
On the language level, `#` is a special sign that the field is private. We can't access it from outside or from inheriting classes.
225+
در سطح زبان، `#` نمادی خاص است که یعنی فیلد خصوصی است. ما نمی‌توانیم از بیرون یا از کلاس‌های ارث‌بر به آن دسترسی داشته باشیم.
226226

227-
Private fields do not conflict with public ones. We can have both private `#waterAmount` and public `waterAmount` fields at the same time.
227+
فیلدهای خصوصی با فیلدهای عمومی ناسازگار نیستند. می‌توانیم در یک زمان هم `#waterAmount` خصوصی داشته باشیم و هم `waterAmount` عمومی.
228228

229-
For instance, let's make `waterAmount` an accessor for `#waterAmount`:
229+
برای مثال، بیایید `waterAmount` را به عنوان اکسسر برای `#waterAmount` ایجاد کنیم:
230230

231231
```js run
232232
class CoffeeMachine {
@@ -246,29 +246,29 @@ class CoffeeMachine {
246246
let machine = new CoffeeMachine();
247247

248248
machine.waterAmount = 100;
249-
alert(machine.#waterAmount); // Error
249+
alert(machine.#waterAmount); // ارور
250250
```
251251

252-
Unlike protected ones, private fields are enforced by the language itself. That's a good thing.
252+
برخلاف محافظت‌شده‌ها، فیلدهای خصوصی در سطح خود زبان اجرایی شده‌اند. این چیز خوبی است.
253253

254-
But if we inherit from `CoffeeMachine`, then we'll have no direct access to `#waterAmount`. We'll need to rely on `waterAmount` getter/setter:
254+
اما اگر ما از `CoffeMachine` ارث‌بری کنیم، سپس دسترسی مستقیم به `#waterAmount` نداریم. باید به سراغ getter/setter برای `waterAmount` برویم:
255255

256256
```js
257257
class MegaCoffeeMachine extends CoffeeMachine {
258258
method() {
259259
*!*
260-
alert( this.#waterAmount ); // Error: can only access from CoffeeMachine
260+
alert( this.#waterAmount ); // ممکن است CoffeMachine ارور: دسترسی فقط از
261261
*/!*
262262
}
263263
}
264264
```
265265

266-
In many scenarios such limitation is too severe. If we extend a `CoffeeMachine`, we may have legitimate reasons to access its internals. That's why protected fields are used more often, even though they are not supported by the language syntax.
266+
در بسیاری از سناریوها چنین محدودیتی خیلی سخت‌گیرانه است. اگر ما `CoffeMachine` را تعمیم دهیم، شاید دلایل قابل قبولی برای دسترسی به درون آن داشته باشیم. به همین دلیل فیلدهای محافظت‌شده اغلب اوقات استفاده می‌شوند حتی اگر آن‌ها توسط سینتکس زبان پشتیبانی نمی‌شوند.
267267

268-
````warn header="Private fields are not available as this[name]"
269-
Private fields are special.
268+
````warn header="فیلدهای خصوصی به صورت this[name] در دسترس نیستند"
269+
فیلدهای خصوصی خاص هستند.
270270
271-
As we know, usually we can access fields using `this[name]`:
271+
همانطور که می‌دانیم، معمولا با استفاده از `this[name]` به فیلدها دسترسی پیدا می‌کنیم:
272272
273273
```js
274274
class User {
@@ -280,7 +280,7 @@ class User {
280280
}
281281
```
282282
283-
With private fields that's impossible: `this['#name']` doesn't work. That's a syntax limitation to ensure privacy.
283+
این برای فیلدهای خصوصی غیر ممکن است: `this['#name']` کار نمی‌کند. این یک محدودیت سینتکسی است تا حریم اطمینان حاصل کند.
284284
````
285285

286286
## Summary

0 commit comments

Comments
 (0)