Advertisement
Guest User

Untitled

a guest
Jun 8th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CoffeeMachine(power, capacity) {
  2.   var waterAmount = 0;
  3.  
  4.   this.waterAmount = function(amount) {
  5.     // вызов без параметра, значит режим геттера, возвращаем свойство
  6.     if (!arguments.length) return waterAmount;
  7.  
  8.     // иначе режим сеттера
  9.     if (amount < 0) {
  10.       throw new Error("Значение должно быть положительным");
  11.     }
  12.     if (amount > capacity) {
  13.       throw new Error("Нельзя залить воды больше, чем " + capacity);
  14.     }
  15.  
  16.     waterAmount = amount;
  17.   };
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement