You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Защищенные свойства обычно начинаются с префикса `_`.**
88
88
89
-
Это не применяется на уровне языка, но существует соглашение, что такие свойства и методы не должны быть доступны извне. Большинство программистов следуют этому.
89
+
Это не синтаксис языка: существует соглашение, что такие свойства и методы не должны быть доступны извне. Большинство программистов следуют этому соглашению.
90
90
91
-
So our property will be called`_waterAmount`:
91
+
Итак, наше свойство будет называться`_waterAmount`:
92
92
93
93
```js run
94
94
classCoffeeMachine {
95
95
_waterAmount =0;
96
96
97
97
setwaterAmount(value) {
98
-
if (value <0) thrownewError("Negative water");
98
+
if (value <0) thrownewError("Отрицательное количество воды");
99
99
this._waterAmount= value;
100
100
}
101
101
@@ -109,16 +109,16 @@ class CoffeeMachine {
109
109
110
110
}
111
111
112
-
//create the coffee machine
112
+
//создаем новую кофеварку
113
113
let coffeeMachine =newCoffeeMachine(100);
114
114
115
-
//add water
116
-
coffeeMachine.waterAmount=-10; // Error: Negative water
115
+
//устанавливаем количество воды
116
+
coffeeMachine.waterAmount=-10; // Error: Отрицательное количество воды
117
117
```
118
118
119
-
Now the access is under control, so setting the water below zero fails.
119
+
Теперь доступ под контролем, поэтому установка воды ниже нуля не удалась.
120
120
121
-
## Read-only "power"
121
+
## Свойство только для чтения "power"
122
122
123
123
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.
0 commit comments