-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
1046 lines (812 loc) · 40.6 KB
/
index.html
File metadata and controls
1046 lines (812 loc) · 40.6 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Types of Functions</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- REVEAL CSS-->
<link rel="stylesheet" href="libs/reveal.js/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="libs/reveal.js/3.8.0/css/reveal.css">
<link rel="stylesheet" href="libs/reveal.js/3.8.0/css/theme/night.css" id="theme">
<link rel="stylesheet" href="libs/reveal.js/3.8.0/plugin/title-footer/title-footer-mod.css" />
<!-- MERMAID-->
<script src="libs/reveal.js/3.8.0/plugin/mermaid/mermaid.min.js"></script>
<style>
.mermaid {
font-size: 0.5em;
}
</style>
<style>
[class*=task-list-item] {
min-height: 22px;
margin-top: 6px!important;
margin-bottom: 6px!important;
padding-left: 0;
list-style: none;
}
[class*=task-list-item]>input:first-child {
position: absolute!important;
opacity: 0;
margin: 0;
}
[class*=task-list-item]>label {
padding-left: 29px!important;
min-height: 22px;
line-height: 22px;
display: inline-block;
position: relative;
vertical-align: top;
margin-bottom: 0;
font-weight: 400;
cursor: pointer;
}
.task-list-item>input:first-child:checked+input[type=hidden]+label::before, .task-list-item>input:first-child:checked+label::before {
background-color: #ecf0f1;
border-color: #ecf0f1;
}
[class*=task-list-item]>input:first-child+input[type=hidden]+label::before, [class*=task-list-item]>input:first-child+label::before {
content: "";
display: inline-block;
position: absolute;
width: 22px;
height: 22px;
border: 1px solid #D3CFC8;
border-radius: 0;
margin-left: -29px;
}
[class*=task-list-item]>input:first-child:checked+input[type=hidden]+label::after, [class*=task-list-item]>input:first-child:checked+label::after {
content: "";
display: inline-block;
position: absolute;
top: 0;
left: 0;
width: 7px;
height: 10px;
border: 2px solid #fff;
border-left: none;
border-top: none;
transform: translate(7.75px,4.5px) rotate(45deg);
-ms-transform: translate(7.75px,4.5px) rotate(45deg);
}
.task-list-item>input:first-child:checked+input[type=hidden]+label::after, .task-list-item>input:first-child:checked+label::after {
border-bottom-color: #95a5a6;
border-right-color: #95a5a6;
}
</style>
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="libs/highlight.js/9.12.0/monokai.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'libs/reveal.js/3.8.0/css/print/pdf.css' : 'libs/reveal.js/3.8.0/css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<style>
/* Solarized Light theme */
.line {
display: block;
}
.line.focus {
background: #fdf6e3;
color: #657b83;
}
/*
.line.focus .hljs-comment,
.line.focus .hljs-quote {
color: #93a1a1;
}
.line.focus .hljs-keyword,
.line.focus .hljs-selector-tag,
.line.focus .hljs-addition {
color: #859900;
}
.line.focus .hljs-number,
.line.focus .hljs-string,
.line.focus .hljs-meta .hljs-meta-string,
.line.focus .hljs-literal,
.line.focus .hljs-doctag,
.line.focus .hljs-regexp {
color: #2aa198;
}
.line.focus .hljs-title,
.line.focus .hljs-section,
.line.focus .hljs-name,
.line.focus .hljs-selector-id,
.line.focus .hljs-selector-class {
color: #268bd2;
}
.line.focus .hljs-attribute,
.line.focus .hljs-attr,
.line.focus .hljs-variable,
.line.focus .hljs-template-variable,
.line.focus .hljs-class .hljs-title,
.line.focus .hljs-type {
color: #b58900;
}
.line.focus .hljs-symbol,
.line.focus .hljs-bullet,
.line.focus .hljs-subst,
.line.focus .hljs-meta,
.line.focus .hljs-meta .hljs-keyword,
.line.focus .hljs-selector-attr,
.line.focus .hljs-selector-pseudo,
.line.focus .hljs-link {
color: #cb4b16;
}
.line.focus .hljs-built_in,
.line.focus .hljs-deletion {
color: #dc322f;
}
.line.focus .hljs-formula {
background: #eee8d5;
}
.line.focus .hljs-emphasis {
font-style: italic;
}
.line.focus .hljs-strong {
font-weight: bold;
}
.yellow-slide .line.focus:nth-child(2) {
background: yellow;
}
.reveal .slides section .code-presenting-annotation {
font-size: 70%;
}
*/
.reveal .slides section .fragment.current-only {
visibility: visible;
display: none;
}
.reveal .slides section .fragment.current-only.current-fragment {
display: block;
}
/*
.line {
display: block;
}
*/
.line.focus {
opacity: 1.0;
}
/* .hljs {
background: none;
} */
/* .reveal pre {
width: 98%;
margin: 0px;
box-shadow: none;
}
.reveal pre code {
font-size: 1.2em;
line-height: 1.2;
border-radius: 10px;
max-height: 60vh !important;
overflow: hidden !important;
} */
@media (device-width: 100vw) and (device-height: 100vh) {
.reveal pre code {
max-height: 50vh !important;
}
}
#logo img {
max-height: 3.5em;
max-width: none;
min-width: 50px;
}
.reveal .slides section .code-presenting-annotation {
color: white;
background: black;
padding: 0px 15px;
border-radius: 15px;
opacity: 0.75 !important;
font-size: 50% !important;
}
</style>
<script>
if (window.location.search.match(/print-pdf-now/gi)) {
window.print();
}
</script>
</head>
<body>
<div id="logo" style="position: fixed; top: 20px; left: 20px; z-index: 1">
<img src="https://raw.githubusercontent.com/HansUXdev/JavaScript-First/2acf5840c15af96602aceb66303ea69c5b75e344/logo.svg" />
</div>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section >
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-176679651-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-176679651-1');
</script>
<link rel="stylesheet" href="theme.css">
<h3><a id="user-content-chapter-overview" class="anchor" href="#chapter-overview" aria-hidden="true"></a>Chapter Overview</h3>
<p>This chapter should cover the following:</p>
<ol>
<li>Anatomy of functions</li>
<li>Catagories of Functions</li>
<li>Simple Examples of Each function</li>
</ol>
</section>
<section >
<h3><a id="user-content-learning-objectives" class="anchor" href="#learning-objectives" aria-hidden="true"></a>Learning Objectives</h3>
<ol>
<li>Explain how you can use hoisted functions?</li>
<li>Explain why you use a return statement?</li>
<li>Explain the difference between Parameters and Arguments</li>
<li>Identify different types of functions</li>
</ol>
</section>
<section >
<h3><a id="user-content-what-is-function" class="anchor" href="#what-is-function" aria-hidden="true"></a>What is Function?</h3>
<p class="fragment">A functions is block of reusable code to preform a task.</p>
<p class="fragment"><a href="https://developer.mozilla.org/en-US/docs/Glossary/First-class_Function">First-class object</a> and are treated just like any other variable</p>
</section>
<section >
<h3><a id="user-content-catagories-of-functions" class="anchor" href="#catagories-of-functions" aria-hidden="true"></a>Catagories of Functions</h3>
<p class="fragment"><strong>1. Synchronous Functions</strong></p>
<p class="fragment"><strong>2. Async Functions</strong></p>
<p class="fragment"><strong>3. Object Oriented Functions</strong></p>
</section>
<section >
<h3><a id="user-content-synchronous-functions" class="anchor" href="#synchronous-functions" aria-hidden="true"></a>Synchronous Functions</h3>
<ol>
<li>Function Declaration</li>
<li>Function Expression</li>
<li>Anonymous Functions</li>
<li>Arrow Functions</li>
<li>Curried Function</li>
<li>Closure</li>
<li>IFFE</li>
</ol>
</section>
<section >
<h3><a id="user-content-async-functions" class="anchor" href="#async-functions" aria-hidden="true"></a>Async Functions</h3>
<ol>
<li>Callbacks</li>
<li>Promises</li>
<li>Generator</li>
<li>Async / Await</li>
<li>Async Generator</li>
</ol>
</section>
<section >
<h3><a id="user-content-object-oriented-functions" class="anchor" href="#object-oriented-functions" aria-hidden="true"></a>Object Oriented Functions</h3>
<ol>
<li>Constructor</li>
<li>Class</li>
</ol>
</section>
<section >
<h4><a id="user-content-function-declaration-vs-function-expression-" class="anchor" href="#function-declaration-vs-function-expression-" aria-hidden="true"></a><strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">Function Declaration</a></strong> VS <strong><a href="https://developer.mozilla.org/en-US/docs/web/JavaScript/Reference/Operators/function#:~:text=A%20function%20expression%20is%20very,expressions%20to%20create%20anonymous%20functions.">Function Expression</a></strong> :</h4>
<p class="fragment current-only" data-code-focus="1-3">This is a <strong>Function DECLARATION</strong>,</p>
<p class="fragment current-only" data-code-focus="5-6">This is a <strong>Functions EXPRESSION</strong></p>
<p class="fragment current-only" data-code-focus="7-8">This is a <strong>ANONYMOUS Functions</strong></p>
<div class="flex-slide">
<div class="column" class="block">
<pre><code class="language-JavaScript">function add(param1, param2){
return param1 + param2;
};
add(1, 2) //returns a value of 3
// Expression
const name = function(){/*Code Block*/}
// Anonymous Functions
function(){ /*Code Block*/ }
</code></pre>
<p></p>
</div>
<div class="double-column" class="block">
<!-- Has the following Features: -->
<p class="fragment current-only" data-code-focus="1-3"><strong>Block Syntax</strong>, with <code>{}</code> at the begining and the end of the function and usually followed by a <code>;</code></p>
<ul>
<li class="fragment current-only" data-code-focus="1-1"><strong>Function</strong> keyword</li>
<li class="fragment current-only" data-code-focus="1-1">Name of function, <code>add</code> is on the right of the function keyword</li>
<li class="fragment current-only" data-code-focus="1-1">Parameters <code>(param1, param2)</code>, which act as variables inside the functions definition.</li>
</ul>
<p class="fragment current-only" data-code-focus="2-2"><strong>Return</strong> keyword, ends the function
and the result is returned</p>
<ul>
<li class="fragment current-only" data-code-focus="4-4">
<p>Function must be called before it runs</p>
</li>
<li class="fragment current-only" data-code-focus="4-4">
<p>When the function is called, we pass values into the <strong>arguements</strong> <code>(1,2)</code></p>
</li>
<li class="fragment current-only" data-code-focus="1-2">
<p>When the function is called, we pass values into the <strong>arguements</strong> <code>(1,2)</code></p>
</li>
<li class="fragment current-only" data-code-focus="1-3">
<p>Function <strong>DECLARATIONS</strong>, are always hoisted.</p>
</li>
</ul>
<!-- Function Expression -->
<p class="fragment current-only" data-code-focus="6-6">The main difference is where the function <code>name</code> is place.</p>
<p class="fragment current-only" data-code-focus="6-6">when function <code>name</code> is placed on the left hand side of the <code>function</code> keyword, its an expression.</p>
<p class="fragment current-only" data-code-focus="6-6"><code>function</code> <strong>expressions</strong> are hoisted in the browserm but not in node.</p>
<p class="fragment current-only" data-code-focus="7-8">In an Expression, the name can be ommitted in order to make it <strong>Anonymous</strong></p>
<p class="fragment">This usually used as a callback or inside and IFFE.</p>
<!-- Anonymous Functions -->
<p class="fragment">This usually used as a callback or inside and IFFE.</p>
<p></p>
</div>
</div>
</section>
<section >
<h3><a id="user-content-arrow-functions" class="anchor" href="#arrow-functions" aria-hidden="true"></a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow</a> Functions</h3>
<pre><code class="language-javascript"> // named arrow function
const name = (params) => {
console.log(params,"named");
}
// multiline
() => {
console.log("multiline");
}
// single line
(a,b,c) => console.log("single");
a => console.log(a);
</code></pre>
<p class="fragment current-only" data-code-focus="1-4">This is an <strong>expression</strong> using an arrow function expressin</p>
<p class="fragment current-only" data-code-focus="5-8">This is the <strong>Anonymous</strong> version.</p>
<p class="fragment current-only" data-code-focus="10-10">The <code>()</code> are used for multiple parameters and the <code>{}</code> can be ommitted.</p>
<p class="fragment current-only" data-code-focus="11-11">The <code>()</code> can be ommitted.</p>
</section>
<section >
<h3><a id="user-content-iife-immediately-invoked-function-expression" class="anchor" href="#iife-immediately-invoked-function-expression" aria-hidden="true"></a><a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE">IIFE</a> (Immediately Invoked Function Expression)</h3>
<!-- Help them: remember -->
<p class="fragment current-only" data-code-focus="1-1">We start with two parentheses <code>()()</code>.</p>
<p class="fragment current-only" data-code-focus="2-3">Then add an anonymous function, inside the first <code>()</code>. </p>
<p class="fragment current-only" data-code-focus="1-10">Can you <strong>identify the lines of anonymous function</strong>? </p>
<div class="fragment fade-out" class="block">
<pre><code class="language-javascript"> // ()()
// (function(){})()
// (()=>{})()
(
function () {
var foo = "bar";
console.log(foo);
}
)
();
</code></pre>
<p></p>
</div>
<div class="fragment fade-in-then-out" class="block">
<p>This is what you normally see:</p>
<pre><code class="language-javascript"> (function () {
var foo = "bar";
console.log(foo);
})();
</code></pre>
<p></p>
</div>
<div class="fragment fade-in-then-out" class="block">
<p>Increasingly more common:</p>
<pre><code class="language-javascript"> (()=> {
var foo = "bar";
console.log(foo);
})();
</code></pre>
<p></p>
</div>
</section>
<section >
<!-- This example i straight from MDN -->
<h3><a id="user-content-closure" class="anchor" href="#closure" aria-hidden="true"></a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#:~:text=A%20closure%20is%20the%20combination,state%20(the%20lexical%20environment).&text=In%20JavaScript%2C%20closures%20are%20created,created%2C%20at%20function%20creation%20time.">Closure</a></h3>
<p>is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment).</p>
<pre><code class="language-javascript">function init() {
var name = 'Mozilla';
function displayName() {
console.log(name);
}
displayName();
}
init();
</code></pre>
<!-- Help them: remember -->
<p class="fragment current-only" data-code-focus="2-2"><code>name</code> is function scoped to the function <code>init()</code></p>
<p class="fragment current-only" data-code-focus="3-5">displayName() is the inner function, a closure</p>
<p class="fragment current-only" data-code-focus="4-4">using the <code>name</code> variable which is in the parent function, <code>init()</code></p>
</section>
<section >
<h3><a id="user-content-currying" class="anchor" href="#currying" aria-hidden="true"></a><a href="https://javascript.info/currying-partials">Currying</a></h3>
<blockquote class="fragment current-only">
<p>is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(x)(y)(z).</p>
</blockquote>
<p>Student Steps:</p>
<p class="fragment current-only">Step 1: Inside <code>0-student_files/chp1/</code> create a file called <code>closureScoped</code>…</p>
<p class="fragment current-only" data-code-focus="1-12">Step 2: Duplicate the code the slide</p>
<p class="fragment current-only" data-code-focus="1-12">Step 3: In your own words, explain how <code>code</code> works in a tweet, using #JavaScriptFIrst.</p>
<pre><code class="language-javascript">function closureScoped(job) {
if (job=="student") {
return (name) => console.log(`my name is ${name} my job is study this code`)
}
else if (job=="teacher") {
return (name) => console.log(`my name is ${name} my job is ${job}`)
}
else {
return () => console.log(`I'm not paying attention because my job is ${job}`)
}
}
closureScoped("designer")("hans");
</code></pre>
<!-- Instructor Steps: -->
<p class="fragment current-only" data-code-focus="1-11">Step 1: Define the function.</p>
<p class="fragment current-only" data-code-focus="2-4">Step 2: Write a conditional if statement.</p>
<p class="fragment current-only" data-code-focus="3-3">Step 3: return an <strong>anonymous arrow function</strong> with a <code>name</code> parameter.</p>
<p class="fragment current-only" data-code-focus="3-3">By <strong>returning</strong> the <code>(name)=></code>, the function <code>closureScoped();</code> gets access to <code>("hans")</code> argument.</p>
<p class="fragment current-only" data-code-focus="5-10">Step 4: finish with some funny else if statements</p>
</section>
<section >
<!-- ### Pure Function
* Its return value is the same for the same arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams from I/O devices).
```JavaScript
```
This defines the doument type as html. {.fragment .current-only data-code-focus=1-1}
* Its evaluation has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams). -->
<p><a href="https://developer.mozilla.org/en-US/docs/Glossary/Callback_function">Callbacks</a></p>
<blockquote class="fragment current-only">
<p>is a function that receives another function name, as an <strong>arguement</strong> when it is called…</p>
</blockquote>
<p>Student Steps:</p>
<p class="fragment current-only">Step 1: Inside <code>0-student_files/chp1/</code> create a file called <code>callbacks.js</code>…</p>
<p class="fragment current-only" data-code-focus="1-12">Step 2: Duplicate the code the slide</p>
<p class="fragment current-only" data-code-focus="1-12">Step 3: In your own words, explain how <code>code</code> works in a tweet, using <code>#JavaScriptFirst</code>.</p>
<pre><code class="language-javascript">function callbackFunction(var1, callback) {
callback(var1);
}
callbackFunction(
1,
function (x) { console.log(x) }
)
</code></pre>
<p>Explain the function:</p>
<p class="fragment current-only" data-code-focus="1-3">Step 1: Define the function.</p>
<p class="fragment current-only" data-code-focus="4-8">Step 2: Use the function.</p>
<p class="fragment current-only" data-code-focus="6-6">Note that <code>1</code> is the first arguement.</p>
<p class="fragment current-only" data-code-focus="7-7">Note that <code>function (x) { console.log(x) }</code> is the second arguement, when <code>callbackFunction()</code> is used.</p>
</section>
<section >
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a></p>
<!-- Source: [FCC](https://www.freecodecamp.org/news/javascript-es6-promises-for-beginners-resolve-reject-and-chaining-explained/) -->
<p>Student Steps:</p>
<p class="fragment current-only fragment current-only" data-code-focus="1-9" data-code-focus="1-1">Step 1: Inside <code>0-student_files/chp1/</code> create a file called <code>promises.js</code></p>
<pre><code class="language-javascript">const myPromise = new Promise((resolve, reject) => {
let condition;
if(condition is met) {
resolve('Promise is resolved successfully.');
} else {
reject('Promise is rejected');
}
});
</code></pre>
<p class="fragment">I promise I’ll write more on this… {.fragment}
Remember, I’m a javascript dev and used to rejection…</p>
</section>
<section >
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator">Generator</a></p>
<blockquote class="fragment current-only">
<p>is returned by a generator function and it conforms to both the iterable protocol and the iterator protocol.</p>
</blockquote>
<p>Student Steps:</p>
<p class="fragment current-only fragment current-only" data-code-focus="1-5" data-code-focus="1-1">Step 1: Inside <code>0-student_files/chp1/</code> create a file called <code>generators.js</code></p>
<pre><code class="language-javascript">function* generator() {
yield 1;
yield 2;
yield 3;
}
const gen = generator();
</code></pre>
</section>
<section >
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">Async Functions</a></p>
<pre><code class="language-javascript">(async ()=> {
try {
// let something = await fetch();
const URI = 'https://www.breakingbadapi.com/api/characters/1';
const DATA = await fetch(URI);
const json = await DATA.json();
console.log(json);
}
catch (error) {
console.log(error)
}
finally {
// settled (fulfilled or rejected)
}
})();
</code></pre>
<p class="fragment current-only" data-code-focus="1-1">Begin the IIFE with <code>async</code></p>
<p class="fragment current-only" data-code-focus="11-11">ENd the IIFE</p>
<p class="fragment current-only" data-code-focus="2-10">Add Try, Catch, Finally</p>
<p class="fragment current-only" data-code-focus="2-4">Write your code in <code>Try</code> statement</p>
<p class="fragment current-only" data-code-focus="2-10">Use Catch to handle the errors and reject Promises</p>
<p class="fragment current-only" data-code-focus="2-10">Then in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally">Finally</a> block handle </p>
<p class="fragment current-only" data-code-focus="2-10">Add Try, Catch, Finally</p>
<p class="fragment current-only" data-code-focus="1-1">This defines the doument type as html.</p>
</section>
<section>
<section >
<h3><a id="user-content-object-oriented-functions-1" class="anchor" href="#object-oriented-functions-1" aria-hidden="true"></a>Object Oriented Functions</h3>
<p>This will get it’s own chapter later, in <strong>Design Patterns</strong>.</p>
</section>
<section >
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function">Constructor Function</a></p>
<blockquote class="fragment current-only">
<p>Sometimes we need a “blueprint” for creating many objects of the same “type”.</p>
</blockquote>
<pre><code class="language-javascript">function Person(first, last, age) {
this.firstName = first;
this.lastName = last;
this.age = age;
}
const myFather = new Person("John", "Doe", 50, "blue");
</code></pre>
<p class="fragment current-only" data-code-focus="1-5">This is our constructor function.</p>
<p class="fragment current-only" data-code-focus="2-4">The keyword <code>THIS</code>, is essentially a reference to itself and the main way you can remember it is a constructor.</p>
</section>
<section >
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">Class</a></p>
<blockquote class="fragment current-only">
<p>“Classes are a template for creating object”</p>
</blockquote>
<pre><code class="language-javascript">class Person {
constructor(first, last, age) {
this.first = first;
this.last = last;
this.age = age;
}
}
let me = new Person("John", "Doe", 50);
</code></pre>
<p class="fragment current-only" data-code-focus="1-8">The is a “class” version of our previous constructor.</p>
<p class="fragment current-only" data-code-focus="1-8">A JavaScript class does not work like classes in other languages. They are just an alternitive syntax.</p>
</section>
</section>
<section >
<h3><a id="user-content-thank-you-for-reading" class="anchor" href="#thank-you-for-reading" aria-hidden="true"></a>Thank You for reading…</h3>
<p>If you liked this you can always read more on github by clicking the image below…</p>
<!-- <p align="center">
<a href="https://github.com/HansUXdev/JavaScript-First">
<img src="https://raw.githubusercontent.com/HansUXdev/JavaScript-First/2acf5840c15af96602aceb66303ea69c5b75e344/logo.svg" height="300px" alt="HTTP Protocol"/>
</a>
</p> -->
<p><strong>You can view more content here:</strong></p>
<a href="https://medium.com/@hansOnConsult" class="MEDIUM">
<img src="https://img.shields.io/badge/medium-%2312100E.svg?&style=for-the-badge&logo=medium&logoColor=white" />
</a>
<a href="https://dev.to/hansuxdev" class="DEV TO">
<img src="https://img.shields.io/badge/DEV.TO-%230A0A0A.svg?&style=for-the-badge&logo=dev-dot-to&logoColor=white" />
</a>
<a href="https://www.youtube.com/channel/UCCGfELkPCJg1XHxQfFFz7pw/about" class="YOUTUBE">
<img src="https://img.shields.io/badge/youtube-%23FF0000.svg?&style=for-the-badge&logo=youtube&logoColor=white" />
</a>
<a href="https://www.youtube.com/channel/UCCGfELkPCJg1XHxQfFFz7pw/about" class="Twitch">
<img src="https://img.shields.io/twitch/status/hansoncoding?style=for-the-badge" />
</a>
</section>
</div>
</div>
<script src="libs/reveal.js/3.8.0/lib/js/head.min.js"></script>
<script src="libs/reveal.js/3.8.0/js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
controlsTutorial: true,
controlsLayout: 'bottom-right',
controlsBackArrows: 'faded',
progress: true,
slideNumber: true,
history: true,
keyboard: true,
overview: true,
center: true,
touch: true,
loop: true,
rtl: false,
shuffle: false,
fragments: true,
fragmentInURL: false,
embedded: false,
help: true,
showNotes: false,
autoPlayMedia: false,
autoSlide: 50000,
autoSlideStoppable: true,
autoSlideMethod: Reveal.navigateNext,
defaultTiming: 120,
mouseWheel: false,
hideAddressBar: true,
previewLinks: false,
transition: 'slide',
transitionSpeed: 'default',
backgroundTransition: 'default',
viewDistance: 3,
parallaxBackgroundImage: '',
parallaxBackgroundSize: '',
parallaxBackgroundHorizontal: 0,
parallaxBackgroundVertical: 0,
display: 'block',
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
// { src: 'libs/reveal.js/3.8.0/lib/js/classList.js', condition: function () { return !document.body.classList; } },
// { src: 'libs/reveal.js/3.8.0/plugin/markdown/marked.js', condition: function () { return !!document.querySelector('[data-markdown]'); } },
// { src: 'libs/reveal.js/3.8.0/plugin/markdown/markdown.js', condition: function () { return !!document.querySelector('[data-markdown]'); } },
// { src: 'libs/reveal.js/3.8.0/plugin/highlight/highlight.js', async: true, callback: function () { hljs.initHighlightingOnLoad(); } },
{ src: 'libs/reveal.js/3.8.0/plugin/notes/notes.js', async: true },
{ src: 'libs/reveal.js/3.8.0/plugin/chart/Chart.min.js' },
{ src: 'libs/reveal.js/3.8.0/plugin/chart/csv2chart.js' },
{ src: 'libs/reveal.js/3.8.0/plugin/embed-tweet/embed-tweet.js' },
{ src: 'libs/reveal.js/3.8.0/plugin/math/math.js', async: true },
{ src: 'libs/highlight.js/9.12.0/highlight.js', async: true },
{ src: 'libs/reveal.js/3.8.0/plugin/anything/anything.js' },
{ src: 'libs/reveal.js/3.8.0/plugin/mermaid/mermaid.min.js', async: true, callback: function() {mermaid.initialize({startOnLoad:false})} },
{ src: 'libs/reveal.js/3.8.0/plugin/search/search.js', async: true },
{ src: 'libs/reveal.js/3.8.0/plugin/zoom-js/zoom.js', async: true },
{ src: 'libs/reveal.js/3.8.0/plugin/title-footer/title-footer.js', async: true, callback: function () { title_footer.initialize(); } },
{
src: 'libs/highlight.js/9.12.0/reveal-code-focus-1.0.0-mod.js',
async: true,
callback: function () {
RevealCodeFocus();
}
},
// { src: 'libs/reveal.js/3.8.0/plugin/reveal-code-focus/highlight.pack.js' },
// { src: 'libs/reveal.js/3.8.0/plugin/reveal-code-focus/reveal-code-focus.js', async: true, callback: function() { RevealCodeFocus(); } },
// {src: 'libs/reveal.js/3.8.0/plugin/line-numbers/line-numbers.js'}
]
,
keyboard: {
67: function () { RevealChalkboard.toggleNotesCanvas() }, // toggle notes canvas when 'c' is pressed
66: function () { RevealChalkboard.toggleChalkboard() }, // toggle chalkboard when 'b' is pressed
46: function () { RevealChalkboard.clear() }, // clear chalkboard when 'DEL' is pressed
8: function () { RevealChalkboard.reset() }, // reset chalkboard data on current slide when 'BACKSPACE' is pressed
68: function () { RevealChalkboard.download() }, // downlad recorded chalkboard drawing when 'd' is pressed
},
math: {
// mathjax: 'libs/reveal.js/3.8.0/plugin/math/MathJax.js',
mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js',
config: 'TeX-AMS_HTML-full'
},
chart: {
defaults: {
global: {
title: { fontColor: "#FFF" },
legend: {
position: "bottom",
labels: { fontColor: "#FFF" },
},
tooltips: {
labels: { fontColor: "#FFF" },
},
},
scale: {
scaleLabel: { fontColor: "#FFF" },
gridLines: { color: "#FFF", zeroLineColor: "#FFF" },
ticks: { fontColor: "#FFF" },
}
},
line: { borderColor: ["rgba(20,220,220,.8)", "rgba(220,120,120,.8)", "rgba(20,120,220,.8)"], "borderDash": [[5, 10], [0, 0]] },
bar: { backgroundColor: ["rgba(20,220,220,.8)", "rgba(220,120,120,.8)", "rgba(20,120,220,.8)"] },
pie: { backgroundColor: [["rgba(0,0,0,.8)", "rgba(220,20,20,.8)", "rgba(20,220,20,.8)", "rgba(220,220,20,.8)", "rgba(20,20,220,.8)"]] },
radar: { borderColor: ["rgba(20,220,220,.8)", "rgba(220,120,120,.8)", "rgba(20,120,220,.8)"] },
},
anything: [
{
className: "mermaid"
},
// ...
],
menu: {
// Specifies which side of the presentation the menu will
// be shown. Use 'left' or 'right'.
side: 'left',
// Specifies the width of the menu.
// Can be one of the following:
// 'normal', 'wide', 'third', 'half', 'full', or
// any valid css length value
width: 'normal',
// Add slide numbers to the titles in the slide list.
// Use 'true' or format string (same as reveal.js slide numbers)
numbers: false,
// Specifies which slide elements will be used for generating
// the slide titles in the menu. The default selects the first
// heading element found in the slide, but you can specify any
// valid css selector and the text from the first matching
// element will be used.
// Note: that a section data-menu-title attribute or an element
// with a menu-title class will take precedence over this option
titleSelector: 'h1, h2, h3, h4, h5, h6',
// If slides do not have a matching title, attempt to use the
// start of the text content as the title instead
useTextContentForMissingTitles: false,
// Hide slides from the menu that do not have a title.
// Set to 'true' to only list slides with titles.
hideMissingTitles: false,
// Adds markers to the slide titles to indicate the
// progress through the presentation. Set to 'false'
// to hide the markers.
markers: true,
// Specify custom panels to be included in the menu, by
// providing an array of objects with 'title', 'icon'
// properties, and either a 'src' or 'content' property.
// custom: false,
custom: [],
// Specifies the themes that will be available in the themes
// menu panel. Set to 'true' to show the themes menu panel
// with the default themes list. Alternatively, provide an
// array to specify the themes to make available in the
// themes menu panel, for example...
// [
// { name: 'Black', theme: 'css/theme/black.css' },
// { name: 'White', theme: 'css/theme/white.css' },
// { name: 'League', theme: 'css/theme/league.css' }
// ]
themes: false,
// Specifies the path to the default theme files. If your
// presentation uses a different path to the standard reveal
// layout then you need to provide this option, but only
// when 'themes' is set to 'true'. If you provide your own
// list of themes or 'themes' is set to 'false' the
// 'themesPath' option is ignored.
themesPath: 'css/theme/',
// Specifies if the transitions menu panel will be shown.
// Set to 'true' to show the transitions menu panel with
// the default transitions list. Alternatively, provide an
// array to specify the transitions to make available in
// the transitions panel, for example...
// ['None', 'Fade', 'Slide']
transitions: false,
// Adds a menu button to the slides to open the menu panel.
// Set to 'false' to hide the button.
openButton: true,
// If 'true' allows the slide number in the presentation to
// open the menu panel. The reveal.js slideNumber option must
// be displayed for this to take effect
openSlideNumber: false,