-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
747 lines (631 loc) · 34.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>M&M Presentation</title>
<!-- Library -->
<script type="text/javascript" src="bower_components/reveal.js/js/reveal.min.js"></script>
<script src="bower_components/reveal.js/lib/js/head.min.js"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&skin=sunburst&lang=css" defer="defer"></script>
<link rel="stylesheet" href="bower_components/reveal.js/css/reveal.min.css">
<!-- <link rel="stylesheet" href="bower_components/reveal.js/css/print/pdf.css"> -->
<link rel="stylesheet" href="css/main.css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-background="#00AAD2">
<h1>M&M</h1>
<h2>Mean Milano</h2>
<img src="images/MM_logo.png" height="160" width="160" alt="">
</section>
<section data-background="#00AAD2">
<h1>REAL LIFE ES6</h1>
<ul class="block" style="margin-right: 160px;">
<li><img src="images/gl.jpg" height="80" width="80" alt=""></li>
<li>Giovanni Lela</li>
<li>CTO @ LinkMe</li>
</ul>
<ul class="block">
<li><img src="images/ms.jpg" height="80" width="80" alt=""></li>
<li>Matteo Scandolo</li>
<li>MEAN Dev @ LinkMe</li>
</ul>
</section>
<!-- ========================================================== JS History ===================================================== -->
<section data-background="#F0DB4F" class="dark-content">
<section>
<h1>Javascript</h1>
<h2>An introduction</h2>
</section>
<section>
<h1>Javascript</h1>
<h3>is a dynamic computer programming language.</h3>
</section>
<section>
<h1>Javascript</h1>
<ul class="block">
<li>is (kind of) object oriented</li>
<li>is functional</li>
<li>is event based</li>
</ul>
</section>
<section>
<h1>JavaScript</h1>
<img src="images/Brendan_Eich.jpg">
<p>Was invented by Brendan Eich in May 1995.<br> (in ten days and not in one night)</p>
</section>
<section>
<h1>JavaScript</h1>
<img src="images/JavaScript-logo.png">
<p>Has been developed for Netscape</p>
<p>And it has been realesed in Netscape 2 in September.</p>
</section>
<section>
<h2>Maybe it was a bit immature...</h2>
<ul class="block">
<li>
<code class="prettyprint">
x = 1.0000000000000001 <br>
(x === 1) // true
</code>
</li>
<li>
<code class="prettyprint">
x = ['10', '10', '10']; <br>
x.map(parseInt) //[10, Nan, 2]
</code>
</li>
</ul>
</section>
<section>
<h1>Javascript</h1>
<img src="images/ecma.jpg">
<p>Became an ECMA standard in 1997.</p>
<p>It is also know as ECMA-262</p>
</section>
<section>
<h1>ECMAScript</h1>
<h3>Standard specification for the language</h3>
<h3>Derived languages born</h3>
<ul class="block">
<li>ActionScript (Adobe)</li>
<li>JScript (Microsoft)</li>
</ul>
</section>
<section>
<h1>Versions</h1>
<ul class="block">
<li>ES3 - 1999 (regEx - Try, Catch)</li>
<li>ES4 - tageted 2008, never saw the light...</li>
<li>ES5 - 2009 (Json, Bind, Map, ...)</li>
<li>ES6 - 2014?</li>
</ul>
</section>
<section>
<h1>Javascript Arise</h1>
<h4>Web 2.0 - Ajax - Google Maps (2005)</h4>
<h4>Js on the server - NodeJs (2009)</h4>
</section>
</section>
<!-- ========================================================== Perchè ES6 Gio ===================================================== -->
<section>
<section>
<h1> Why ES6? </h1>
</section>
<section>
<h1> Why change javascript?</h1>
<ul>
<li> Stagnation is a social ill</li>
<li> It breeds frustration</li>
<li> New solutions arise</li>
</ul>
</section>
<section>
<h1> Responding to stagnation </h1>
<p> Some solutions are good </p>
<p> Others are bad </p>
</section>
<section>
<h1> Evolving the standard is best</h1>
<p> Everybody is going to ship javascript </p>
</section>
<section>
<img src="images/jsturd.png">
</section>
</section>
<!-- ========================================================== BASIC ES6 ===================================================== -->
<section>
<section>
<h1>Road to ES6</h1>
<h3>Some interesting Features</h3>
</section>
<!-- ========================================================== Template Strings ===================================================== -->
<section>
<h2>Template Strings</h2>
<p>Allows string literals with embedded expressions in them.</p>
<code class="prettyprint">
var name = "Matteo";<br>
console.log(`Hello, ${name}!`);
</code>
</section>
<section>
<h2>In Practice</h2>
<code class="prettyprint">
<div id="js-element">initial content</div><br>
<script><br>
var name = "Matteo";<br>
var element = document.getElementById('js-element');<br>
element.innerHTML = `Hello, ${name}!`;<br>
</script>
</code>
</section>
<!-- ========================================================== Default Parameters ===================================================== -->
<section>
<h2>Default Parameter Value</h2>
<p>Default parameter values allow you to initialize parameters if they were not explicitly supplied. <br>This means that you no longer have to do <i>x = x || {};</i></p>
<code class="prettyprint">
var f = function(x = 5){return x + 1};<br>
<!-- var f = (x = 5) => x + 1; -->
</code>
</section>
<section>
<h2>In Practice</h2>
<code class="prettyprint">
var getUser = function(id = 'me'){ <br>
$.get('api/user/' + id, <br>
function(res){return res}, <br>
function(e){throw new Error(e)} <br>
); <br>
}
</code>
</section>
<!-- ========================================================== Arrow Functions ===================================================== -->
<section>
<h2>Arrow Functions</h2>
<p>The goal of Arrow Functions is to address and resolve several common pain points of traditional Function Expression:</p>
<ul>
<li>Lexical this binding</li>
<li>Shorter syntactical form</li>
</ul>
<code class="prettyprint">
//before <br>
var f = function(x){return x + 1;} <br>
//es6 <br>
var f = x => x+1;
<br><br>
console.log(f(2));
</code>
</section>
<section>
<h2>In Practice</h2>
<code class="prettyprint">
var user; <br><br>
getUser() <br>
.then( <br>
res => user = res, <br>
e => throw new Error(e) <br>
); <br>
</code>
</section>
<!-- ========================================================== REST ===================================================== -->
<section>
<h2>REST</h2>
<p>Rest parameters provide a cleaner way of dealing with functions that takes arbitrary number of parameters than using arguments. <br>
Basically your parameters are convertend in an array </p>
<code class="prettyprint">
var f = function(...args){ <br>
var tot = 0; <br>
for (var i = 0; i < args.length; i++ ){ <br>
tot += args[i]; <br>
} <br>
return tot/args.length; <br>
} <br>
<br> <br>
f(12, 8, 16, 32); //17
</code>
</section>
<section>
<h2>In Practice</h2>
<code class="prettyprint">
var cart = {list: []}; <br>
cart.add = function(...items){ <br>
items.forEach(item => this.list.push(item)); <br>
}; <br>
<br>
cart.add('ball'); <br>
cart.add('tree', 'soap');
<br><br>
console.log(cart.list);
</code>
</section>
<!-- ========================================================== SPREAD ===================================================== -->
<section>
<h2>SPREAD</h2>
<p>The spread construct allows an expression to be expanded in places where multiple arguments are expected</p>
<code class="prettyprint">
var args = [12, 99, 17] <br>
var f = (x, y, z) => Math.min(x, y, z);<br>
f(...args);
</code>
</section>
<section>
<h2>In practice</h2>
<code class="prettyprint">
var inputs = [1,2,3]; <br><br>
function f(x, y, z) { <br>
return x + y + z; <br>
} <br><br>
f(...inputs);
</code>
</section>
<section>
<h2>In Practice</h2>
<p>This example rely on <a href="https://github.com/petkaantonov/bluebird">Bluebird</a> and <a href="https://lodash.com">Lodash</a></p>
<code class="prettyprint">
var targetFunction = _.curry(function(a,b,c)); <br>
targetFunction('Hello'); <br>
<br>
var functionList = [fn1, fn2]; <br>
// fn1 => return name | fn2 => return surname;<br>
Promise //bluebird <br>
.all(functionList) //accept an array of Promise <br>
.then( function(res){ //receive an array <br>
//spread the array into arguments <br>
targetFunction(...res); <br>
}); <br>
</code>
</section>
</section>
<!-- ========================================================== ADVANCED ES6 (GIO) ===================================================== -->
<section>
<section>
<h1>Road to ES6</h1>
<h3>Some more interesting Features</h3>
</section>
<section>
<h1> Block scoping </h1>
</section>
<section>
<h2> Hoisting </h2>
<code class="prettyprint">
function f() { <br>
doSomething(); <br>
var a = 1; <br>
}
</code>
<code class="prettyprint">
function f() { <br>
var a; <br>
doSomething(); <br>
a = 1; <br>
}
</code>
</section>
<section>
<code class="prettyprint">
for (var i = 0; i < 3; i++) { <br>
var j = 1 * i; <br>
console.log(j); //0 //1 //2<br>
} <br>
console.log(j); // 3
</code>
<code class="prettyprint">
for (var i = 0; i < 3; i++) { <br>
let j = 1 * i; <br>
console.log(j); //0 //1 //2<br>
} <br>
console.log(j); // will throw ReferenceError
</code>
</section>
<section>
<h2>Dangers of hoisting </h2>
<p> Don't make functions within a loop </p>
<code class="prettyprint">
var elems = document.getElementsByClassName('myClass'), i; <br>
<br>
for (i = 0; i < elems.length; i++) { <br>
elems[i].addEventListener('click', function () { <br>
this.innerHTML = i; <br>
}); <br>
}
</code>
</section>
<section>
<h2> Before: ugly scoping magic </h2>
<code class="prettyprint">
var elems = document.getElementsByClassName('myClass'), i; <br>
<br>
function makeClickHandler(i) { <br>
return function () { <br>
this.innerHTML = i; <br>
}; <br>
} <br>
<br>
for (i = 0; i < elems.length; i++) { <br>
elems[i].addEventListener("click", makeClickHandler(i)); <br>
}
</code>
</section>
<section>
<h2>Now: let to the rescue </h2>
<code class="prettyprint">
for (let i = 0; i < elems.length; i++) { <br>
elems[i].addEventListener("click", function () { <br>
this.innerHTML = i; <br>
}); <br>
}
</code>
</section>
<section>
<h2>Const</h2>
<p> The same as let but:</p>
<ul>
<li> It must be initialized </li>
<li> And just once </li>
</ul>
<code class="prettyprint">
const CONSTANT; //error <br><br>
const CONSTANT = "Wow, I am constant"; <br><br>
CONSTANT = "No you are not"; //error
</code>
</section>
<section>
<h1>Iterators, generators and the callback hell</h1>
</section>
<section>
<h2>Iterator</h2>
<p>An Iterator is an object that knows how to access items from a collection one at a time, while keeping track of its current position within that sequence<p>
<code class="prettyprint">
var lang = { name: 'JavaScript', birthYear: 1995 }; <br>
var it = Iterator(lang); <br><br>
var pair = it.next(); // Pair is ["name", "JavaScript"] <br>
pair = it.next(); // Pair is ["birthYear", 1995] <br>
pair = it.next(); // A StopIteration exception is thrown
</code>
</section>
<section>
<h2> Iterable </h2>
<code class="prettyprint">
function Words(str) { <br>
this._str = str; <br>
} <br><br>
Words.prototype[Symbol.iterator] = function() { <br>
var re = /\S+/g; <br>
var str = this._str; <br>
return { <br>
next: function() { <br>
var match = re.exec(str); <br>
if (match) { <br>
return {value: match[0], done: false}; <br>
} <br>
return {value: undefined, done: true}; <br>
} <br>
} <br>
};
</code>
</section>
<section>
<h2> for..of </h2>
<code class="prettyprint">
var helloWorld = new Words("Hey you"); <br>
for (var word of helloWorld) { <br>
console.log(word); <br>
} <br><br>
//Hey <br>
//you
</code>
<br>
<p> Works also on arrays, maps, sets.. </p>
</section>
<section>
<h1>Generators</h1>
<ul>
<li>A very special kind of iterators</li>
<li>It's an iterator whose results are determined by an iterator function </li>
</ul>
</section>
<section>
<h2>Iterating on a generator</h2>
<code class="prettyprint">
function* countdown(){ <br>
yield 2; //first next()<br>
yield 1; //second next() <br>
yield 0; //third next() <br>
//done <br>
} <br><br>
let generatorObject = countdown(); <br><br>
generatorObject.next(); // {value : 2, done : false} <br>
generatorObject.next(); // {value : 1, done : false} <br>
generatorObject.next(); // {value : 0, done : false} <br>
generatorObject.next(); // {value : undefined, done : true}
</code>
</section>
<section>
<h2> Talking back to a generator </h2>
<code class="prettyprint small">
function* countdown(){ <br>
let one = yield 2; //first next()<br>
console.log(one); //one <br>
let two = yield 1; //second next <br>
console.log(two); //two <br>
let three = yield 0; //third next <br>
console.log(three); //three <br>
//done! <br>
} <br><br>
let generatorobject = countdown(); <br><br>
generatorobject.next(); // {value : 2, done : false} <br>
generatorobject.next('one'); // {value : 1, done : false} <br>
generatorobject.next('two'); // {value : 0, done : false} <br>
generatorobject.next('three'); // {value : undefined, done : true}
</code>
</section>
<section>
<h2>Hello promises</h2>
<ul>
<li>A promise is an object which represents the results of a future computation </li>
<li>It allows to take action when the async operation is done</li>
</ul>
</section>
<section>
<h2> Using a promise </h2>
<code class="prettyprint">
var awesomePromise = getAsyncThings(); <br>
awesomePromise.then( <br>
//resolve <br>
function(value){ <br>
console.log('yeah :' + value); <br>
}, <br>
//reject <br>
function(error){ <br>
console.log('oh no'); <br>
console.log(error); <br>
} <br>
);
</code>
</section>
<section>
<h2>Creating a promise </h2>
<code class="prettyprint extra-small">
function getAsyncThings(url) { <br>
// Return a new promise. <br>
return new Promise(function(resolve, reject) { <br>
// Do the usual XHR stuff <br>
var req = new XMLHttpRequest(); <br>
req.open('GET', url); <br>
req.onload = function() { <br>
// This is called even on 404 etc so check the status <br>
if (req.status === 200) { <br>
// Resolve the promise with the response text <br>
resolve(req.response); <br>
} <br>
else { <br>
// Otherwise reject with the status text which will hopefully be a meaningful error <br>
 reject( new Error(req.statusText)); <br>
} <br>
}; <br>
// Handle network errors <br>
req.onerror = function() { <br>
reject( new Error('Network Error')); <br>
}; <br>
// Make the request <br>
req.send(); <br>
}); <br>
}
</code>
</section>
<section>
<h2> Chaining promises </h2>
<code class="prettyprint">
getStuff('stuff.json') <br>
.then(function(story){ <br>
return saveInSomeDatabase(); <br>
}) <br>
.then(function(success){ <br>
console.log('saved!'); <br>
});
</code>
</section>
<section>
<h2> Promises + generators = .. </h2>
<code class="prettyprint small">
var gen = generator(); <br><br>
//get the party started <br>
var generatedPromise = gen.next().value; <br><br>
//when the promise is resolved call the next step <br><br>
function nextStep(){ <br>
generatedPromise.then(function(promiseResult){ <br>
gen.next(promiseResult); <br>
});<br>
} <br><br>
//loop me <br>
nextStep();
</code>
</section>
<section>
<h2> (Semi) coroutines </h2>
<code class="prettyprint">
Promise.coroutine(function* () { <br>
var tweets = yield $.get('tweets.json'); <br>
var profile = yield $.get('profile.json'); <br>
var friends = yield $.get('friends.json'); <br>
console.log(tweets, profile, friends); <br>
})();
</code>
</section>
</section>
<section>
<section>
<h2>Suggested readings</h2>
<ul class="block">
<li>Compatibility Table <a href="http://kangax.github.io/compat-table/es6/">http://kangax.github.io/compat-table/es6/</a></li>
<li>History of Javascript <a href="http://dailyjs.com/history-of-javascript.html">http://dailyjs.com/history-of-javascript.html</a></li>
<li>The Birth and Death of Javascript <a href="https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript">https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript</a></li>
<li>LightWeight ES6 Features <a href="http://colintoh.com/blog/lightweight-es6-features">http://colintoh.com/blog/lightweight-es6-features</a></li>
<li>Use ES6 Today <a href="http://code.tutsplus.com/articles/use-ecmascript-6-today--net-31582">http://code.tutsplus.com/articles/use-ecmascript-6-today--net-31582</a></li>
<li>Block Scope <a href="http://ariya.ofilabs.com/2013/05/es6-and-block-scope.html">http://ariya.ofilabs.com/2013/05/es6-and-block-scope.html</a> (and related posts)</li>
<li>ES6 Feature Proposal <a href="http://tc39wiki.calculist.org/es6/">http://tc39wiki.calculist.org/es6/</a></li>
<li>Promises A+ <a href="https://promisesaplus.com/">https://promisesaplus.com/</a></li>
</ul>
</section>
</section>
<!-- ========================================================== NEXT ===================================================== -->
<section data-background="#00AAD2">
<h2>Server Side JS</h2>
<ul class="block">
<li>
<em>
Real Life examples on Server Side programming
</em>
</li>
<li>
<b>20th January 2015</b> - <em>7:00 pm</em>
</li>
<li>
<i>Place to be defined</i>
</li>
</ul>
</section>
<!-- ========================================================== Hiring ===================================================== -->
<section data-background="#186D69">
<section>
<h2>M&M Milano !== LinkMe</h2>
</section>
<section>
<h4>But...we are looking for an experienced Node Developer</h4>
<h2>
Write @
<a href="mailto: [email protected]">[email protected]</a>
</h2>
</section>
</section>
</div>
</div>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
width: 1200,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // none/fade/slide/convex/concave/zoom
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'bower_components/reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'bower_components/reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'bower_components/reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'bower_components/reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'bower_components/reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'bower_components/reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>