-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
245 lines (209 loc) · 6.78 KB
/
index.html
File metadata and controls
245 lines (209 loc) · 6.78 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html>
<body>
<h2>Creating Objects and class
</h2>
<pre>
<code> 'use strict'
class Polygon {
constructor(height, width) {
this.h = height;
this.w = width;
}
test() {
console.log("The height of the polygon: ", this.h)
console.log("The width of the polygon: ", this.w)
}
}
//creating an instance
var polyObj = new Polygon(10, 20);
polyObj.test();
class Recrengel {
constructor(rwidth, rheight) {
this.rw = rwidth;
this, rh = rheight;
}
createRec() {
console.log("The height of the polygon: ", this.rh)
console.log("The width of the polygon: ", this.rw)
}
}
//creating an instance
var recObj = new Recrengel(100, 80);
myrec = recObj.createRec();
console.log("rectangle: " + myrec);
</code>
</pre>
<script>
'use strict'
class Polygon {
constructor(height, width) {
this.h = height;
this.w = width;
}
test() {
console.log("The height of the polygon: ", this.h)
console.log("The width of the polygon: ", this.w)
}
}
//creating an instance
var polyObj = new Polygon(10, 20);
polyObj.test();
console.log("rectangle: " + myrec);
class Recrengel {
constructor(rwidth, rheight) {
this.rw = rwidth;
this.rh = rheight;
}
createRec() {
// console.log("The height of the polygon: ", this.rh)
// console.log("The width of the polygon: ", this.rw)
return this.rh * this.rw;
}
}
//creating an instance
var recObj = new Recrengel(100, 80);
var myrec = recObj.createRec();
console.log("rectangle: " + myrec);
</script>
<script>
'use strict'
class PrinterClass {
doPrint() {
console.log("doPrint() from Parent called…")
}
}
class StringPrinter extends PrinterClass {
doPrint() {
super.doPrint()
console.log("doPrint() is printing a string…")
}
}
var obj = new StringPrinter()
obj.doPrint()
</script>
<h2>
Promises and Callbacks.
</h2>
<pre>
function notifyAll(fnSms, fnEmail) {
setTimeout(function() {
console.log('starting notification process');
fnSms();
fnEmail();
}, 2000);
}
notifyAll(
function() {
console.log("Sms send ..");
},
function() {
console.log("email send ..");
}
);
console.log("End of script"); //executes first or not blocked by others
</pre>
<script>
function notifyAll(fnSms, fnEmail) {
setTimeout(function() {
console.log('starting notification process');
fnSms();
fnEmail();
}, 2000);
}
notifyAll(
function() {
console.log("Sms send ..");
},
function() {
console.log("email send ..");
}
);
console.log("End of script"); //executes first or not blocked by others
</script>
<h2>Understanding Callback
</h2>
<pre>
<code>
function getSum(n1, n2) {
var isAnyNegative = function() {
return n1 < 0 || n2 < 0;
}
var promise = new Promise(function(resolve, reject) {
if (isAnyNegative()) {
reject(Error("Negatives not supported"));
}
resolve(n1 + n2);
});
return promise;
}
getSum(5, 6)
.then(function(result) {
console.log(result);
return getSum(10, 20);
//this returns another Promise
},
function(error) {
console.log(error);
})
.then(function(result) {
console.log(result);
return getSum(30, 40);
//this returns another Promise
},
function(error) {
console.log(error);
})
.then(function(result) {
console.log(result);
},
function(error) {
console.log(error);
});
console.log("End of script ");
</code>
</pre>
<script>
function getSum(n1, n2) {
var isAnyNegative = function() {
return n1 < 0 || n2 < 0;
}
var promise = new Promise(function(resolve, reject) {
if (isAnyNegative()) {
reject(Error("Negatives not supported"));
}
resolve(n1 + n2);
});
return promise;
}
getSum(5, 6)
.then(function(result) {
console.log("1st res: " + result);
return getSum(10, 20);
//this returns another Promise
},
function(error) {
console.log("1st error: " + error);
})
.then(function(result) {
console.log("2nd res: " + result);
return getSum(30, -40);
//this returns another Promise
},
function(error) {
console.log("2nd error: " + error);
})
.then(function(result) {
console.log("3rd res: " + result);
},
function(error) {
console.log("3rd error: " + error);
});
console.log("End of script ");
</script>
<script>
import display_message from 'MessageModule.js'
display_message()
</script>
</body>
</html>