Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CoffeeMachine(power, capacity) {
- var waterAmount = 0;
- this.waterAmount = function(amount) {
- // вызов без параметра, значит режим геттера, возвращаем свойство
- if (!arguments.length) return waterAmount;
- // иначе режим сеттера
- if (amount < 0) {
- throw new Error("Значение должно быть положительным");
- }
- if (amount > capacity) {
- throw new Error("Нельзя залить воды больше, чем " + capacity);
- }
- waterAmount = amount;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement