This commit is contained in:
Ilya Kantor 2014-11-16 01:40:20 +03:00
parent 962caebbb7
commit 87bf53d076
1825 changed files with 94929 additions and 0 deletions

View file

@ -0,0 +1 @@
[edit src="solution"/]

View file

@ -0,0 +1,55 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
function Machine(power) {
this._enabled = false;
this.enable = function() {
this._enabled = true;
};
this.disable = function() {
this._enabled = false;
};
}
function CoffeeMachine(power) {
Machine.apply(this, arguments);
var waterAmount = 0;
var timerId;
this.setWaterAmount = function(amount) {
waterAmount = amount;
};
function onReady() {
alert('Кофе готов!');
}
var parentDisable = this.disable;
this.disable = function() {
parentDisable.call(this);
clearTimeout(timerId);
}
this.run = function() {
if (!this._enabled) {
throw new Error("Кофеварка выключена");
}
timerId = setTimeout(onReady, 1000);
};
}
var coffeeMachine = new CoffeeMachine(10000);
coffeeMachine.run();
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
# Останавливать кофеварку при выключении
[importance 5]
Когда кофеварку выключают -- текущая варка кофе должна останавливаться.
Например, следующий код кофе не сварит:
```js
var coffeeMachine = new CoffeeMachine(10000);
coffeeMachine.enable();
coffeeMachine.run();
coffeeMachine.disable(); // остановит работу, ничего не выведет
```
Реализуйте это на основе решения [предыдущей задачи](/task/coffeemachine-fix-run).