-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstruct.js
More file actions
46 lines (38 loc) · 1.19 KB
/
construct.js
File metadata and controls
46 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// let obj = {};
// function A() {
// return obj;
// }
// function B() {
// return obj;
// }
// let a = new A();
// let b = new B();
// alert(a == b); // true
// function Calculator() {
// this.read = function () {
// this.a = +prompt('Введите а...', '');
// this.b = +prompt('Введите b...', '');
// };
// this.sum = function () {
// // sum = a + b;
// return this.a + this.b;
// };
// this.mul = function () {
// // mul = a * b;
// return this.a * this.b;
// };
// };
// let calculator = new Calculator();
// calculator.read();
// alert('Sum = ' + calculator.sum());
// alert('Mul = ' + calculator.mul());
function Accumulator(startingValue) {
this.value = startingValue;
this.read = function () {
return this.value += +prompt('Enter num...', '')
}
}
let accumulator = new Accumulator(1); // начальное значение 1
accumulator.read(); // прибавит ввод prompt к текущему значению
accumulator.read(); // прибавит ввод prompt к текущему значению
alert(accumulator.value); // выведет сумму этих значений