en.javascript.info/1-js/8-oop/2-internal-external-interface/1-add-method-property-coffeemachine/solution.md
2015-06-13 00:13:43 +03:00

42 lines
703 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Кофеварка с новым методом:
```js
//+ run
function CoffeeMachine(power) {
this.waterAmount = 0;
var WATER_HEAT_CAPACITY = 4200;
*!*
var timerId;
*/!*
var self = this;
function getBoilTime() {
return self.waterAmount * WATER_HEAT_CAPACITY * 80 / power;
}
function onReady() {
alert( 'Кофе готово!' );
}
this.run = function() {
*!*
timerId = setTimeout(onReady, getBoilTime());
*/!*
};
*!*
this.stop = function() {
clearTimeout(timerId)
};
*/!*
}
var coffeeMachine = new CoffeeMachine(50000);
coffeeMachine.waterAmount = 200;
coffeeMachine.run();
coffeeMachine.stop(); // кофе приготовлен не будет
```