-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe-code.js
64 lines (53 loc) · 1.21 KB
/
the-code.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// -- the app --
let handler = {
add: function() {
controller.add(a, b);
}
};
let controller = {
add: function(a, b) {
let lastResult = model.getLastResult();
let result = logic.add(a, b, lastResult);
model.setLastResult(result);
view.render(result);
}
};
let model = {
lastResult: 0,
setLastResult: function(new_last_result) {
this.lastResult = new_last_result;
},
getLastResult: function() {
return this.lastResult;
},
};
let logic = {
add: function(a, b, lastResult) {
let result = 0;
if (a === undefined && b === undefined) {
result = lastResult;
} else if (b === undefined) {
result = a + lastResult;
} else if (a === undefined){
result = b + lastResult;
} else {
result = a + b;
}
return result;
}
};
let view = {
render: function(result) {
console.log(result);
}
};
// modify the variable declarations to pass arguments through the calc
let a = undefined;
let b = undefined;
handler.add(); // -> ?
a = 2;
handler.add(); // -> ?
b = -1;
handler.add(); // -> ?
a = undefined;
handler.add(); // -> ?