-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·1028 lines (885 loc) · 30.6 KB
/
index.html
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>Modern Web Development with JavaScript</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<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">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/serif.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Custom styles -->
<link rel="stylesheet" href="css/styles.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Modern Web Development with JavaScript</h1>
<p>
<h3><a href="http://rovolutionary.com/">Rohit Kalkur</a></h3>
</p>
</section>
<section>
<h2>Prerequisites</h2>
<ul>
<li>Understanding of how a web application works</li>
<li>Web application development experience in another language/framework (Java Spring, Ruby on Rails, PHP etc...)</li>
</ul>
</section>
<section>
<h2>Course Objectives</h2>
<ul>
<li>JavaScript Foundations</li>
<li>Lab</li>
<li>Client-server Interaction</li>
<li>DOM Manipulation</li>
<li>Lab</li>
<li>Lunch?</li>
<li>Application Architecture</li>
<li>Backbone.js</li>
<li>Angular.js</li>
<li>Lab - Choose either Backbone.js or Angular.js lab</li>
<li>Advanced Concepts</li>
<li>Wrap Up</li>
</ul>
</section>
<!-- Course content STARTS here -->
<!-- JavaScript Refresher -->
<section>
<section>
<h2>History of JavaScript</h2>
<ul>
<li>Created by Netscape engineer Brendan Eich in April 1995</li>
<li>First called Mocha and then LiveScript</li>
<li>Has nothing to do with Java despite the name!</li>
</ul>
</section>
<section>
<h2>How It Works</h2>
<ul>
<li>HTML page has <code><script></script></code> tags where JavaScript code is written</li>
<li>JavaScript is an interpreted language, so the code immediately executed after being loaded into browser</li>
<li>JavaScript can also be loaded in from external files</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
<!DOCTYPE html>
<html ng-app>
<head>
<script>
alert("Running this JavaScript!") //Immediately triggers an alert box when the page is loaded
</script>
<script type="text/javascript" src="main.js"></script> <!-- Loads in an external script -->
</head>
<body>
</body>
</html>
</code></pre>
</section>
<section>
<h2>JavaScript - Primitive Data Types</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Variable Initialization/Declaration */
var myNumber = 5;
var myString = "myString";
var myBoolean = false;
/* Print Output To Debug Console */
console.log("my number is " + myNumber); // Output: "my variable is 5"
console.log("my string is " + myString); // Output: "my string is myString"
console.log( typeof myNumber ); // Output: "number"
console.log( typeof myString ); // Output: "string"
console.log( typeof myBoolean ); // Output: "boolean"
</code></pre>
</section>
<section>
<h2>JavaScript - Objects</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Object Initialization/Declaration */
var obj = {
"prop1" : 5,
prop2 : "value of property 2"
};
obj.prop3 = false; // Add a property to an already defined object
console.log( obj.prop1 ); // Output: 5
console.log( obj["prop2"] ); // Output: "value of property 2"
console.log( typeof obj ); // Output: "object"
</code></pre>
</section>
<section>
<h2>JavaScript - Arrays</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Array Initialization/Declaration */
var myArray = [1, 3, 4];
myArray.push(5); // Appends 5 to myArray
myArray.pop(); // Remove the last value in the Array and returns it
myArray.length; // Returns the number of elements in the Array
/* Array is a type of object */
console.log( typeof myArray ); // Output: "object"
</code></pre>
</section>
<section>
<h2>JavaScript - Boolean Logic</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Basic Comparison Operators */
var a = 1;
var b = 2;
console.log( a > b ); // Output: false
console.log( a < b); // Output: true
console.log( a <= 1 ); // Output: true
console.log( a >= 1 ); // Output: true
/* Strict vs Loose Type Checking */
console.log( 0 == false ); // Output: true (loose check)
console.log( 0 === false ); // Output: false (strict check)
console.log( 0 != false ); // Output: false (loose check)
console.log( 0 !== false ); // Output: true (strict check)
</code></pre>
</section>
<section>
<h2>JavaScript - Conditionals</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* If-Else Statement */
var age = 15;
if(age < 21) {
console.log("You CANNOT drink legally in the United States!");
console.log("Go drink a soda!");
} else if(age === 21) {
console.log("Its your first of being able to drink alcohol legally!");
console.log("Be responsible!");
} else {
console.log("You are older than 21.");
console.log("Still be responsible!");
}
// Output:
// console.log("You CANNOT drink legally in the United States!");
// console.log("Go drink a soda!");
/* Ternary Statement */
var val = (0 <= 15) ? "less than or equal to" : "greater than";
console.log(val); // Output: "less than or equal to"
</code></pre>
</section>
<section>
<h2>JavaScript - Loops</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* For loop */
for(var i = 0; i < 5; i++) {
console.log(i);
}
/* Output: prints the numbers 0-4 */
/* While loop */
var i = 0;
while (i<5) {
console.log(i);
i++;
}
/* Output: prints the numbers 0-4 */
/* Loop through object properties */
var myObject = { prop1 : 1, prop2 : 2, prop3 : 3 };
for(var key in myObject) {
console.log("key: " + key + ", value: " + myObject[key]);
}
/* Output: prints each key, value pair
"key: prop1, value: 1"
"key: prop2, value: 2"
"key: prop3, value: 3"
*/
</code></pre>
</section>
<section>
<h2>JavaScript - Functions</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Function Initialization/Declaration */
function myFunction() {
if(arguments[0]) {
console.log("This is my function with arg " + arguments[0]);
} else {
console.log("This is my function!");
}
}
myFunction(); // Output: "This is my function!"
myFunction(1); // Output: "This is my function with arg 1"
var mySecondFunction = function(arg) {
console.log("This is my other function with arg " + arg);
};
mySecondFunction(2); // Output: "This is my other function with arg 2"
(function() {
console.log("Immediately Invoked Function Expression (IIFE)");
})() // Output: "Immediately Invoked Function Expression (IIFE)"
// Can add functions as properties to an object
var myCoolObject = {};
myCoolObject.printFoo = function() {
console.log("Foo");
};
</code></pre>
</section>
<section>
<h2>JavaScript - Context</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
var user = {
name : "Al Grasso",
printName : function() {
console.log("Username: " + this.name);
}
}
user.printName(); /* Output: "Username: Al Grasso" */
</code></pre>
</section>
<section>
<h2>JavaScript - Prototypical Inheritance</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* Base prototype */
var fruit = {
"color" : null,
"shape" : null,
"price" : 1.50
}
/* Orange constructor */
function Orange() {
this.color = "orange";
this.shape = "round";
this.makeJuice = function() {
console.log("Made orange juice!");
}
}
Orange.prototype = fruit;
/* Bananas constructor */
function Banana() {
this.color = "yellow";
this.shape = "long curving cylinder";
}
Banana.prototype = fruit;
var myOrange = new Orange();
var myBanana = new Banana();
console.log(myOrange.color); // Output: "orange"
console.log(myBanana.color); // Output: "yellow"
console.log(myOrange.price); // Output: 1.50
console.log(myBanana.price); // Output: 1.50
myOrange.makeJuice(); // Output: "Made orange juice!"
myBanana.makeJuice(); // TypeError: Object #<Banana> has no method 'makeJuice'
console.log( myOrange instanceof Orange ) // Output: true
console.log( myOrange instanceof Object ) // Output: true
console.log( myOrange instanceof Banana ) // Output: false
</code></pre>
</section>
<section>
<h2>JavaScript - Prototypical Inheritance</h2>
<img src="img/protypical_inheritance.png"></img>
</section>
<section>
<h2>JavaScript - Scope</h2>
<ul>
<li>Established within each function</li>
<li>'var' keyword scopes variable to the function it is contained within</li>
<li>If reference not found in current scope, the above scope is checked</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
var a = 1;
function funcOne() {
a = 2;
}
funcOne();
console.log(a); // Output: 2
var b = 1;
function funcTwo() {
var b = 2;
}
funcTwo();
console.log(b); // Output: 1
function funcThree() {
function funcFour() {
console.log("Four");
}
funcFour();
}
funcThree(); // Output: "Four"
funcFour(); // ReferenceError: funcFour is not defined
</code></pre>
</section>
<section>
<h2>JavaScript - Hoisting</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
function printA() {
console.log(a);
var a = 1;
}
printA(); // Output: Any guesses? Try inputting it into the console
printNumber(4); // Output: "The number is 4"
function printNumber(num) {
console.log("The number is " + num);
}
printFoo(4); // TypeError: undefined is not a function
var printFoo = function(foo) {
console.log(foo);
}
</code></pre>
</section>
<section>
<h2>JavaScript - Exception Throwing/Handling</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
function throwError(message) {
throw Error("ERROR: " + message);
}
try {
console.log("This will print to the console");
throwError("You've got problems!");
console.log("This will not print to the console");
} catch(error) {
console.log(error.message); // Output: "You've got problems!"
}
</code></pre>
</section>
<section>
<h2>JavaScript - Element Selection & Event Binding (via JQuery)</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/*
Select the HTML element with id = element1 & bind a click event to it
*/
$("#element1").on('click', function(e) {
e.preventDefault();
console.log("clicked on element1!");
});
/*
Unbind the 'click' event from all elements with the class tag 'listing'
*/
$(".listing").off('click');
</code></pre>
</section>
<section>
<h2>Reminders</h2>
<ul>
<li>Always scope your variables!</li>
<li>Everything except the primitive data types (number, boolean, string) is an object!</li>
<li>use <code>null</code> (instead of <code>undefined</code>) to mean 'having no value'</li>
<li>Always use strict comparison operators!</li>
</ul>
</section>
<section>
<h2>Lab Time - JavaScript</h2>
<a href="labs/lab1.html" target="_blank">Click to begin lab</a>
</section>
</section> <!-- End of JavaScript refresher section -->
<section><!-- Beginning of Client-server interaction section -->
<section>
<h2>JavaScript Back In the Day</h2>
<ul>
<li><a href='http://codepen.io/yahtaa/full/lrnhd'>Vintage BSB</a></li>
<li><a href='http://codepen.io/lesleyburr/full/yGgco'>Clueless Fan Page</a></li>
</ul>
</section>
<section>
<h2>JavaScript Today!</h2>
<ul>
<li><a href='http://tweetmap.it/'>Tweet Map</a></li>
<li><a href='http://www.rleonardi.com/interactive-resume/'>Interactive Resume</a></li>
</ul>
</section>
<section>
<ul>
<li>As browsers have evolved over time, so has JavaScript feature set</li>
<li>More application logic now being done on the client-side itself</li>
<li>Primary benefits are to speed and performance</li>
</ul>
</section>
<section>
<h2>HTML</h2>
<ul>
<li><strong>H</strong>yper<strong>T</strong>ext <strong>M</strong>arkup <strong>L</strong>anguage</li>
<li>Markup language for web browsers</li>
<li>Used to define structure and layout for web pages</li>
</ul>
</section>
<section>
<h2>DOM</h2>
<ul>
<li><strong>D</strong>ocument <strong>O</strong>bject <strong>M</strong>odel</li>
<li>API for interacting with HTML markup as objects</li>
<li>HTML is just text, DOM is what we use to interface with it</li>
<li>Often times the terms (HTML, DOM) are used interchangeably</li>
</ul>
</section>
<section>
<h2>JSON</h2>
<ul>
<li><strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation</li>
<li>Data format based on JavaScript objects</li>
<li>Note: Keys must be double quoted!</li>
<li>Benefit: Easy to work with in JavaScript!</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
{
"key1" : 1,
"key2" : "two",
"key3" : [1, { "key" : "value" }],
"key4" : true
}
</code></pre>
</section>
<section>
<h2>HTTP</h2>
<ul>
<li><strong>H</strong>yper<strong>t</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol</li>
<li>Method of communicating between client and server sides</li>
<li>Client sends Request, server comes back with Response</li>
<li>Request consists of info such as:
<ul>
<li>Path <span class="custom-highlight-purple">'/path/to/go/to'</span></li>
<li>Method <span class="custom-highlight-purple">GET</span></li>
<li>Parameters <span class="custom-highlight-purple">Key-value pairs</span></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>AJAX</h2>
<ul>
<li><strong>A</strong>synchronous <strong>J</strong>ava<strong>S</strong>cript and <strong>X</strong>ML</li>
<li>Retrieve data from server via HTTP requests</li>
<li>Only update parts of the view as necessary</li>
</ul>
</section>
<section>
<h2>REST</h2>
<ul>
<li><strong>R</strong>epresentational <strong>S</strong>tate <strong>T</strong>ransfer</li>
<li>Design for communicating with server-side via HTTP to manipulate back-end data objects</li>
<li>Uses 4 HTTP methods:
<ul>
<li class="fragment">GET - Retrieve a resource</li>
<li class="fragment">POST - Create a resource</li>
<li class="fragment">PUT - Update a resource</li>
<li class="fragment">DELETE - Delete a resource</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>REST</h2>
<ul>
<li>Example: I want to retrieve the list of users</li>
<li>Request: <span class="custom-highlight-purple">GET '/users'</span></li>
<li>Response: JSON object</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
[
{
"id" : 0,
"username" : "agrasso",
"email" : "[email protected]",
},
{
"id" : 1,
"username" : "rkalkur",
"email" : "[email protected]",
}
]
</code></pre>
</section>
<section>
<h2>REST</h2>
<ul>
<li>Example: I want to delete the user with id 1</li>
<li>Request: <span class="custom-highlight-purple">DELETE '/users/1'</span></li>
<li>Response: JSON object</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">{ "message" : "User rkalkur was deleted!" }
</code></pre>
</section>
<section>
<h2>Broswer Developer Tools</h2>
<ul>
<li>Built into all major browsers</li>
<li>Allows you to:
<ul>
<li>inspect DOM elements</li>
<li>debug JavaScript</li>
<li>track incoming/outcoming HTTP requests</li>
</ul>
</li>
<li>Extremely useful when developing JavaScript!</li>
<li>To access Chrome Developer Tools, right-click and go to "Inspect Element"</li>
</ul>
</section>
<section>
<h2>Traditional Application Structure</h2>
<img src="img/traditional_web_architecture.png"></img>
</section>
<section>
<h2>Single Page Application (SPA)</h2>
<img src="img/single_page_architecture.png"></img>
</section>
<section>
<h2>Lab Time - Client-Server Interaction</h2>
<a href="labs/lab2.html" target="_blank">Click to begin lab</a>
</section>
</section><!-- End of Client-server interaction section -->
<section><!-- Beginning of Client side Frameworks section -->
<section>
<h2></h2>
<ul>
<li>AJAX requests made to REST API to manipulate back-end data resources</li>
<li>Only individual pieces of the DOM are updated as needed</li>
<li>No complete page reload!</li>
</ul>
</section>
<section>
<h2>Benefits of SPA Architecture</h2>
<ul>
<li>View rendering/updating all done on the client-side itself!</li>
<li>Less requests to the server-side = a faster application!</li>
</ul>
</section>
<section>
<h2>JavaScript Client-Side Frameworks</h2>
<ul>
<li>Allows developer to neatly structure client-side codebase</li>
<li>Provides a predefined, out-of-box structure (that can be extended if need be)</li>
<li>Popular frameworks include:
<ul>
<li><a href="http://backbonejs.org/">Backbone</a></li>
<li><a href="http://emberjs.com/">Ember</a></li>
<li><a href="http://angularjs.org/">Angular</a></li>
<li><a href="http://knockoutjs.com/">Knockout</a></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Backbone.js</h2>
<ul>
<li>Created by Jeremy Ashkenas</li>
<li>Client-side code separated into Models, Collections, and Views</li>
</ul>
</section>
<section>
<h2>Backbone.js - Model</h2>
<ul>
<li>Representation of back-end data resources</li>
<li>Responsible for interacting with back-end via REST API</li>
<li>Triggers events when changed</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
var Employee = Backbone.Model.extend({});
/* Create instance of Employee */
var ceo = new Employee({ name : "Al Grasso" });
</code></pre>
</section>
<section>
<h2>Backbone.js - Collection</h2>
<ul>
<li>Set of data models</li>
<li>Can also manipulate resources via REST API (fetch all models, create model)</li>
<li>Triggers events when models are added or removed</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
var EmployeeList = Backbone.Collection.extend({
model: Employee,
url: '/employees'
});
/* Create instance of EmployeeList */
var employees = new EmployeeList();
/* Bind a callback fn to employee's add event */
employees.bind('add', function() {
console.log("Employee was added to employees");
});
/* Fetch list of all employees from server */
employees.fetch(); // Sends HTTP request - GET '/employees'
</code></pre>
</section>
<section>
<h2>Backbone.js - View</h2>
<ul>
<li>Responsible for rendering, updating, and event handling on a section of the DOM</li>
<li>Associated with a model or collection (can bind to events)</li>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
var EmployeeListView = Backbone.View.extend({
events : {
"click li" : "triggerEmployeeClickedMsg" // View event binding
},
initialize : function() {
this.listenTo(this.collection, 'reset', this.render);
},
render : function() {
var thisView = this; // Store view context in thisView
thisView.$el.empty(); // Clear the existing list
// Add each employee to the list
_.each(thisView.collection.models, function(employee) {
var employeeListing = "<li>" + employee.get('name') + "</li>";
thisView.$el.append(employeeListing);
});
},
triggerEmployeeClickedMsg : function() {
alert("Employee listing was clicked!");
}
});
/* Create instance of EmployeeListView */
var employeeListView = new EmployeeListView({
el : 'ul#employeeList' // DOM element that view will correspond to
});
</code></pre>
</ul>
</section>
<section>
<h2>Templating Engines</h2>
<ul>
<li>Problem: In dynamic, data-driven applications, we are contantly adding/updating/removing different parts of the DOM</li>
<li>Need a way to render data-driven HTML views on the client side without page-refresh</li>
<li>Solution: Client-side templating engines!</li>
</ul>
</section>
<section>
<h2>Templating Engines</h2>
<p>Implementations:</p>
<ul>
<li><a href="http://underscorejs.org/">Underscore.js</a></li>
<li><a href="http://handlebarsjs.com/">Handlebars.js</a></li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
<script id="employeeListingTemplate" type="text/template">
<li class="employee-listing">
<div class="name"><@= name @></div> <!-- Outputs the 'name' property of the object passed to the template rendering -->
<div class="email"><@= email @></div>
<ul class="projects">
<@ _.each(projects, function(project) { @> <!-- Can embed code into template if need be -->
<li><@= project.name @></li>
<@ }) @>
</ul>
</li>
</script>
</code></pre>
</section>
<section>
<h2>Templating Engines</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
/* JS Code */
var employeeListingTemplate = $("employeeListingTemplate").html(),
employeeObject = {
"name" : "Frank Johnson",
"email" : "[email protected]"
"projects" : [
{ "name" : "The Super Duper Project" },
{ "name" : "The TOP SECRET Super Duper Project" }
]
},
compiledTemplate = _.template(employeeListingTemplate, employeeObject);
// NOTE: You can now append 'compiledTemplate' to any part of your DOM
</code></pre>
</section>
<section>
<h2>Lab Time - Backbone.js</h2>
<a href="labs/lab3.html" target="_blank">Click to begin lab</a>
</section>
<section>
<h2>Backbone.js - Pros</h2>
<ul>
<li>Provides basic structure for client-side code</li>
<li>Highly customizable</li>
<li>Extension Frameworks:
<ul>
<li><a href="http://marionettejs.com/">Backbone Marionette</a></li>
<li><a href="http://chaplinjs.org/">Chaplin</a></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Backbone.js - Cons</h2>
<h4>Developer is responsible for:</h4>
<ul>
<li>Dereferencing unused objects</li>
<li>Cleaning up event bindings</li>
<li>Keeping view and data models synchronized (boilerplate code)</li>
</ul>
</section>
</section><!-- End of Backbone section -->
<section><!-- Beginning of Angular section -->
<section>
<h2>Angular.js</h2>
<ul>
<li>Created by Google</li>
<li>Automatically synchronizes view with data model (two-way data binding)</li>
</ul>
</section>
<section>
<h2>Angular.js - Template</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
</head>
<body ng-controller="UsersCtrl">
<ul>
<li ng-repeat="user in users">
<div class="name">{{ user.name }}</div>
<div class="email">{{ user.email }}</div>
</li>
</ul>
</body>
</html>
</code></pre>
</section>
<section>
<h2>Angular.js - Controller</h2>
<ul>
<li>Responsible for application logic</li>
<li>Attach properties to $scope object</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
function UsersCtrl($scope, Users) {
$scope.users = Users.query();
}
</code></pre>
</section>
<section>
<h2>Angular.js - Resource</h2>
<ul>
<li>Allows user to interact with with server-side resources via REST</li>
<li>Injected into a controller as a 'service'</li>
<li>Can be extended if need be</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
$resource('/users');
</code></pre>
</section>
<section>
<h2>Lab Time - Angular.js</h2>
<a href="labs/lab4.html" target="_blank">Click to begin lab</a>
</section>
<section>
<h2>Angular.js - Pros</h2>
<ul>
<li>Template Filters</li>
<li>HTML Directives (HTML tags with customizable behavior)</li>
<li>Dependecy Injection</li>
<li>Uses a smaller version of JQuery (JQuery lite)</li>
<li>Naturally supports unit testing</li>
<li>Less boilerplate code = smaller JS code base!</li>
</ul>
</section>
<section>
<h2>Angular.js - Cons</h2>
<p>Steep learning curve!</p>
</section>
</section><!-- End of Angular section -->
<section><!-- Beginning of Extra content section -->
<section>
<h2>Test Driven Development</h2>
<ul>
<li>Write a failing test - given an this input, I expect this output</li>
<li>Implement functionality to pass the test</li>
<li>Tests serve as 'blueprint' for functionality</li>
</ul>
</section>
<section>
<h2>Test Driven Development</h2>
<ul><h4>Pros:</h4>
<li>Clearly defined interfaces</li>
<li>Fewer bugs</li>
<li>Faster development time</li>
</ul>
</section>
<section>
<h2>Test Driven Development</h2>
<ul><h4>Popular Testing Frameworks:</h4>
<li><a href="http://pivotal.github.io/jasmine/">Jasmine BDD</a></li>
<li><a href="http://visionmedia.github.io/mocha/">Mocha</a></li>
</ul>
</section>
<section>
<h2>Module Loading</h2>
<ul>
<li>Problem: All code stored in a single file (typically called app.js or main.js)</li>
<li>Can leads to global namespace conflicts</li>
<li>Difficult to test individual components of codebase</li>
<li>Becomes tough to read code!</li>
</ul>
</section>
<section>
<h2>Module Loading</h2>
<ul>
<li>Solution: Separate code into individual files - modules</li>
<li>Improves testability and performance</li>
<li>Popular implementations:
<ul>
<li><a href="http://requirejs.org/">Require.js</a></li>
<li><a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>CoffeeScript</h2>
<ul>
<li>Alternative syntax that compiles down into JavaScript</li>
<li>Includes cool features such as:
<ul>
<li>more verbose, English-like syntax</li>
<li>default parameter assignment</li>
<li>O.O.P. class structure</li>
</ul>
<li><a href="http://coffeescript.org/">Click here to read more</a></li>
</ul>
</section>
<section>
<h2>JavaScript on the Server-side - Node.js</h2>
<ul>
<li>Runs on the V8 JavaScript engine - same as Chrome</li>
<li>Non-blocking I/O via callbacks</li>
<li>Persistant communication channel between clients and server</li>
</ul>
</section>
</section><!-- End of Extra content section -->
<section>
<h2>About the Textbook</h2>
<img id="textBookCover" src="img/goodPartsCover.png"></img>
<ul id="textBookDescription">
<li>By Douglas Crockford (the father of JSON)</li>
<li>Discusses the "good" and "bad" parts of JS</li>
<li>Describes best practices for writing clean, maintainable JS</li>
<li>A must read for anyone writing lots of JS!</li>
</ul>
</section>
<section>
<h2>Thank You all for attending!</h2>
<h3>I hope you've been inspired to go forth and create cool web apps!</h3>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script src="js/example.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>