Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2532e5

Browse files
authored
Update LESSONPLAN.md
1 parent 95d59aa commit f2532e5

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

Week2/LESSONPLAN.md

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ The purpose of this class is to introduce to the student:
1212

1313
FIRST HALF (12.00 - 13.30)
1414

15-
### 1. The structure and use of `Promises`
15+
## 1. Promises
1616

17-
Notes:
18-
19-
- It's the accepted solution to [callback hell](http://callbackhell.com/)
17+
### Explanation
2018
- It's a way to introduce asynchronicity to your application
2119
- Makes asynchronous code read like it's synchronous
22-
23-
**Show examples**
24-
25-
- First give example about how to create a promise
26-
27-
```
20+
### Example
21+
```javascript
2822
let promiseToDoHomeWork = new Promise(function (resolve, reject) {
2923
let isDone = true;
3024

@@ -40,10 +34,9 @@ promiseToDoHomeWork
4034
.catch(function () { console.log('home work has something wrong, can\'t be done'); })
4135

4236
```
43-
4437
- Nested promises example
4538

46-
```
39+
```javascript
4740

4841
let attendClass = function () {
4942
return new Promise(function (resolve, reject) {
@@ -78,19 +71,19 @@ attendClass()
7871

7972
- Promise.all
8073

81-
```
74+
```javascript
8275
Promise.all([attendClass(), doTheHomeWork(), submitHomework()]).then(function ([res1, res2, res3]) { console.log('all finished') });
8376
```
8477

8578
- Promise.race
8679

87-
```
80+
```javascript
8881
Promise.race([attendClass(), doTheHomeWork(), submitHomework()]).then(function (result) { console.log('one of them finished') });
8982
```
9083

9184
- Example for converting XHR to promise as a preparation for `fetch`
9285

93-
```
86+
```javascript
9487
function fetchResource(url) {
9588
return new Promise(function (resolve, reject) {
9689
const oReq = new XMLHttpRequest();
@@ -117,18 +110,24 @@ fetchResource(`https://api.openweathermap.org/data/2.5/weather?q=amsterdam&appid
117110

118111
```
119112

120-
### 2. How to use the `fetch` API to do AJAX calls
113+
### Excercise
114+
115+
### Essence
116+
117+
- It's the accepted solution to [callback hell](http://callbackhell.com/)
118+
121119

122-
Notes:
120+
## 2. How to use the `fetch` API to do AJAX calls
123121

122+
### Explanation
124123
- Modern replacement of XMLHttpRequest
125124
- Uses Promise structure
126125
- The Fetch API is defined in the browser (window.fetch)
127126
- Only modern browsers support it (show [caniuse.com](https://caniuse.com/#feat=fetch))
128127
- Fetch API documentations by mozilla [link](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
128+
### Example
129129

130-
**Do exercise**
131-
130+
### Excercise
132131
```
133132
fetch('https://seriousnews.com/api/headlines')
134133
.then(function (response) {
@@ -137,21 +136,22 @@ fetch('https://seriousnews.com/api/headlines')
137136
console.log(headlines)
138137
}).catch(error => console.log(error));
139138
```
139+
### Essence
140140

141141
SECOND HALF (14.00 - 16.00)
142142

143-
### 3. The `this` keyword and its relationship with `scope`
144-
145-
Notes:-
143+
## 3. The `this` keyword and its relationship with `scope`
146144

145+
### Explanation
147146
- The environment(or scope) in which the line is being executed is know as “Execution Context”
148147
- The object that `this` refers to, changes every time execution context is changed.
149148
- Whatever is calling the function passes the `this` value to it by default.
150149
- We can pass specific `this` by `.bind`, `.call` or `.apply`
150+
- By default, “this” refers to global object which is `global` in case of NodeJS and `window` object in case of browser
151151

152-
152+
### Example
153153
#### “this” refers to global object
154-
```
154+
```javascript
155155
// Immediately Invoked Function Expression (IIFE)
156156
(function () {
157157
// First Example
@@ -184,7 +184,7 @@ foo(); //prints false on console as in “strict mode” value of “this” in
184184

185185
#### this refers to new instance (constructors)
186186

187-
```
187+
```javascript
188188
function Person(fn, ln) {
189189
this.first_name = fn;
190190
this.last_name = ln;
@@ -203,7 +203,7 @@ person2.displayName(); // Prints Name: Paul Adams
203203
- In Javascript, property of an object can be a method or a simple value.
204204
- When an Object’s method is invoked then “this” refers to the object which contains the method being invoked.
205205

206-
```
206+
```javascript
207207

208208
function foo() {
209209
'use strict';
@@ -270,17 +270,24 @@ person2.displayName(); // Prints Name: Paul Adams
270270
let person2Display = person.displayName.bind(person2); // Creates new function with value of “this” equals to person2 object
271271
person2Display(); // Prints Name: Paul Adams
272272
```
273+
### Excercise
274+
### Essence
275+
273276

274-
### 4. Arrow functions and JS versions
277+
## 4. Arrow functions and JS versions
275278

276-
Notes:
279+
### Explanation
277280
- JS versions https://www.w3schools.com/js/js_versions.asp
278281
- Arrow functions can’t be used as constructors as other functions can.
279282
- If you attempt to use new with an arrow function, it will throw an error.
280283
- To create class-like objects in JavaScript, you should use the new ES6 classes instead
281-
- Arrow func exmaples
282284

283-
```
285+
The this keyword works differently in arrow functions.
286+
287+
- The `this` value inside the arrow function gets binded and calcuated and assigned based on its wrapper/container/parent `this` value.
288+
- The methods call(), apply(), and bind() will not change the value of this in arrow functions
289+
### Example
290+
```javascript
284291
// ES5
285292
var multiplyES5 = function (x, y) {
286293
return x * y;
@@ -289,14 +296,8 @@ var multiplyES5 = function (x, y) {
289296
// ES6
290297
const multiplyES6 = (x, y) => { return x * y };
291298
```
292-
293-
The this keyword works differently in arrow functions.
294-
295-
- The `this` value inside the arrow function gets binded and calcuated and assigned based on its wrapper/container/parent `this` value.
296-
- The methods call(), apply(), and bind() will not change the value of this in arrow functions
297-
298299
#### “this” with fat arrow function
299-
```
300+
```javascript
300301
function Person(fn, ln) {
301302
this.first_name = fn;
302303
this.last_name = ln;
@@ -313,7 +314,7 @@ person1.displayName(); // this doesn't equal window, because it gets `this` that
313314

314315
In the following example, the foo1() gets the `window` as `this` value, because on interpretation time, the interpreter assign the `this` immediately based on the surrounding execution context which is `window` in the case of simple literal object.
315316

316-
```
317+
```javascript
317318
let user = {
318319
count: 10,
319320
foo1: () => {
@@ -324,11 +325,10 @@ let user = {
324325
let user1 = user.foo1() // this equals window
325326
```
326327

327-
## test your knowledge
328-
329-
In this example, let the students guess the result and then go line by line as if you were an interpreter and execute the code. Or use the debugger tools on devtools to execute line by line.
328+
### Excercise
329+
In this excercise, let the students guess the result and then go line by line as if you were an interpreter and execute the code. Or use the debugger tools on devtools to execute line by line.
330330

331-
```
331+
```javascript
332332
function multiply(p, q, callback) {
333333
callback(p * q);
334334
}
@@ -348,11 +348,7 @@ user.findMultiply();
348348
//Prints 6
349349
//Prints true
350350
```
351+
### Essence
352+
351353

352-
## Wrapping up
353354

354-
### `this` rules
355-
- By default, “this” refers to global object which is `global` in case of NodeJS and `window` object in case of browser
356-
- When a method is called as a property of object, then `this` refers to the parent object
357-
- When a function is called with `new` operator then `this` refers to the newly created instance.
358-
- When a function is called using `call` and `apply` functions then `this` refers to the value passed as first argument of call or apply method.

0 commit comments

Comments
 (0)