-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosures.js
More file actions
128 lines (111 loc) · 2.01 KB
/
Closures.js
File metadata and controls
128 lines (111 loc) · 2.01 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//variation 1
// function close() {
// var a = 20;
// return function b() {
// console.log(a);
// };
// }
// var x = close();
// console.log(x);
// x();
//variation 2
// function close2() {
// var a2 = 20;
// function b2() {
// console.log(a2);
// }
// return b2;
// }
// var x2 = close2();
// console.log(x2);
// x2();
//variation 3
// function close3() {
// var a3 = 20;
// function b3() {
// console.log(a3);
// }
// a3 = 50;
// return b3;
// }
// var x3 = close3();
// console.log(x3);
// x3();
//variation 4
// function outer(a) {
// var b = 20;
// function inner(c) {
// console.log(a, b, c);
// }
// return inner;
// }
// outer(10)(30);
//variation 5
// function outer(a) {
// function inner(c) {
// console.log(a, b, c);
// }
// var b = 20;
// return inner;
// }
// outer(10)(30);
//variation 6
// function outer(a) {
// function inner(c) {
// console.log(a, b, c);
// }
// let b = 20;
// return inner;
// }
// outer(10)(30);
// variation 7
// function outest(a) {
// var b = 20;
// function outer(c) {
// function inner(e) {
// console.log(a, b, c, d, e);
// }
// var d = 40;
// return inner;
// }
// return outer;
// }
// outest(10)(30)(50);
//variation 8
// function outest(a) {
// var b = 20;
// function outer(c) {
// let d = 40;
// function inner(e) {
// console.log(a, b, c, d, e);
// }
// return inner;
// }
// return outer;
// }
// let d = 5;
// outest(10)(30)(50);
//data hiding and encapsulation
// function counter() {
// var count = 0;
// this.increase = function () {
// count++;
// };
// this.print = function () {
// console.log(count);
// };
// this.decrease = function () {
// count--;
// };
// }
// var counter1 = new counter();
// counter1.increase();
// counter1.print();
// counter1.increase();
// counter1.print();
// counter1.increase();
// counter1.print();
// counter1.increase();
// counter1.print();
// counter1.decrease();
// counter1.print();