-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
737 lines (593 loc) · 28.1 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>So, what’s new in ES2022? • Christophe Porteneuve @ Confoo Montréal 2020</title>
<meta name="description" content="Yes, okay, ES2015 rules, and ES2017/2018 bring about a lot of cool things (most notably async/await), but a ton of cool stuff is expected to land in the next few years, too… and we can play with it already! Christophe takes you through a whirlwind tour of the upcoming features he’s most excited about, due to become official in 2020, 2021… or 2022 ;-)">
<meta name="author" content="Christophe Porteneuve">
<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 href='css/fonts.css' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/theme/sky.css" id="theme-basis">
<link rel="stylesheet" href="css/theme/pw15.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/prism.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if (window.location.search.match(/print-pdf/gi)) {
var link = document.createElement('link')
link.rel = 'stylesheet'
link.type = 'text/css'
link.href = 'css/print/pdf.css'
document.getElementsByTagName('head')[0].appendChild(link)
}
</script>
</head>
<body id="prioFix">
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section id="mainTitle">
<h1>So, what’s new in ES2022?</h1>
<p>
A presentation by <a href="http://tddsworld.com/">Christophe Porteneuve</a> at <a href="https://confoo.ca/en/yul2020/">Confoo Montréal 2020</a>
</p>
</section>
<section id="whoami">
<h2>whoami</h2>
<pre><code data-trim class="language-js">
const christophe = {
family: { wife: 'Élodie', sons: ['Maxence', 'Elliott'] },
city: 'Paris, FR',
company: 'Delicious Insights',
trainings: ['360° ES', 'Modern Web Apps', 'Node.js', '360° Git', 'Webpack'],
webDevSince: 1995,
mightBeKnownFor: [
'Prototype.js',
'Prototype and Script.aculo.us',
'dotJS',
'Paris Web',
'NodeSchool Paris',
],
}
</code></pre>
</section>
<section id="tc39">
<h1>ES2022 ?!</h1>
<h3>ECMA, TC39, ECMAScript and JavaScript</h3>
</section>
<section id="ecma">
<h2>ECMA and TC39</h2>
<p>
ECMA is an international standards body<br/>
(like ISO, IETF, W3C or WHATWG, to name a few)
</p>
<p>ES = ECMAScript. The official standard for JavaScript*</p>
<p>
TC39 = Technical Committee 39. Caretaker of several standards:<br/>
ECMAScript (ECMA-262), <code>Intl</code> (ECMA-402), JSON (ECMA-404), etc.
</p>
<footer>* Which happens to be, in the U.S., a trademark of Oracle Corp. Yeah, I know 🤢</footer>
</section>
<section id="tc39-process-summary">
<h2>The way the language evolves at TC39</h2>
<p>Meetings every two months, mostly in the U.S. <strong>Yearly</strong> release in June.</p>
<p>“ES6” = ES2015, “ES7” = ES2016, and now we say ES2020, etc.</p>
<p>This is all <a href="https://github.com/tc39">transparent and public</a>.</p>
</section>
<section id="tc39-process-stages">
<h2>The <a href="https://tc39.github.io/process-document/">5 stages</a> of the TC39 process</h2>
<table class="condensed">
<thead>
<tr><th>Stage</th><th>Description</th></tr>
</thead>
<tbody>
<tr>
<th>0 Strawman</th>
<td>“Say, it’d be nifty to get a Unicorn (🦄) operator to…”</td>
</tr>
<tr class="fragment">
<th>1 Proposal</th>
<td>A TC39 member becomes the proposal’s “champion.” The general shape of the API is defined, and most of the <em>cross-cutting concerns</em> are handled.</td>
</tr>
<tr class="fragment">
<th>2 Draft</th>
<td>The initial spec text is done, and covers all critical aspects and the tech semantics.</td>
</tr>
<tr class="fragment">
<th>3 Candidate</th>
<td>The spec is complete, duly reviewed and approved. The API is finalized and no stone is left unturned.</td>
</tr>
<tr class="fragment">
<th>4 Finished</th>
<td>
Full Test262 coverage, 2+ shipped implementations (usually v8 and Spidermonkey), significant real-world feedback, and imprimatur by the Spec Editor. Will then be part of the next feature freeze (January-March), hence ship in the associated yearly release.</td>
</tr>
</tbody>
</table>
</section>
<section id="es2018">
<h1>Quick recap: ES2018</h1>
</section>
<section id="es2018-rest-spread-props">
<h2>ES2018: Rest/Spread properties</h2>
<pre><code class="language-js">
class OldSchoolHOC extends Component {
render() {
// Rest on properties
const { component: Component, <u>...props</u> } = this.props
return (
// …
<Component {...props} />
)
}
}
</code></pre>
<pre class="fragment"><code class="language-js">
// Spread on properties
const DEFAULTS = { first: 'John', last: 'Doe' }
const person = { last: 'Smith', age: 42 }
const result = { <u>...DEFAULTS</u>, <u>...person</u>, age: 36 }
// => { first: 'John', last: 'Smith', age: 36 }
</code></pre>
</section>
<section id="es2018-regexp">
<h2>ES2018: RegExp galore</h2>
<pre><code class="language-js">
// Flag: “dotAll” / “singleLine”
'<p>line 1\nline 2\nline 3</p>'.match(/<p>.*<\/p>/<u>s</u>) // => '<p>…</p>'
</code></pre>
<pre class="fragment"><code class="language-js">
// Named captured groups
const ATTR = /\s+(<u>?<name></u>\w+)=(<u>?<quote></u>['"])(<u>?<value></u>.+?)<u>\k<quote></u>/
const { name, quote, value } = '<p class="foo"></p>'.match(ATTR)<u>.groups</u>
// => name === 'class', quote === '"', value === 'foo'
'<p class="foo"></p>'.replace(ATTR, '[<u>$<name></u>=<u>$<value></u>]')
// => '<p[class=foo]></p>'
</code></pre>
<pre class="fragment"><code class="language-js">
// Lookbehinds (here a positive one)
'$10.53'.match(/(<u>?<=</u>\$)\d+(?:\.\d+)?/) // => ['10:53', …]
</code></pre>
<pre class="fragment"><code class="language-js">
// Unicode Property Escapes
'By Ζεύς!'.match(/<u>\p{Script=Greek}</u>+/<u>u</u>)[0] // => 'Ζεύς'
</code></pre>
</section>
<section id="es2018-finally">
<h2>ES2018: <code>Promise</code>#<code>finally</code></h2>
<p>
Invoked regardless of the promise chain’s outcome (fulfilled or rejected), and does not alter that state.<br/>
So very much like the <code>finally</code> block for a <code>try</code>.
</p>
<pre><code class="language-js">
function doSomeOldSchoolAsync() {
return Promise.resolve()
.then(setUp)
.then(onSuccess, onError)
<u>.finally(anyway)</u>
}
</code></pre>
</section>
<section id="es2018-async-iter">
<h2>ES2018: asynchronous iteration</h2>
<p>
A promise-based variation of the synchronous iteration from ES2015.<br/>
Instead of implementing <code>Symbol.iterator</code>, we implement <code>Symbol.asyncIterator</code>.
</p>
<p>Easily consumable using the new <code>for await (… of …)</code></p>
<p>Node (10+) and WHATWG streams (e.g. Fetch) are asynchronous iterables.</p>
<pre><code class="language-js">
async function echoLines(filename) {
const input = createReadStream(filename, 'utf-8')
<u>for await</u> (const line of input) {
console.log(`> ${line}`)
}
}
</code></pre>
</section>
<section id="es2019">
<h1>Quick recap: ES2019</h1>
</section>
<section id="es2019-optional-catch-binding">
<h2>ES0219: optional <code>catch</code> binding</h2>
<p>Sometimes you don’t need the error…</p>
<pre><code class="language-js">
function safeRequire(pathspec) {
try {
require(pathspec)
} <u>catch</u> {
debug(`Could not load optional dependency ${pathspec}`)
}
}
</code></pre>
</section>
<section id="es2019-fromentries">
<h2>ES2019: <code>Object.fromEntries</code></h2>
<p>The inverse of <code>Object.entries</code>: builds an object from its key/value pairs.</p>
<pre><code class="language-js">
function pick(src, ...propertyNames) {
return <u>Object.fromEntries</u>(
Object.entries(src).filter(([name]) => propertyNames.includes(name))
)
}
</code></pre>
</section>
<section id="es2019-trim-start-end">
<h2>ES2019: <code>String</code>#<code>trimStart/End</code></h2>
<p>Finer-grained variations of ES2015’s <code>trim()</code> that let us pick an extremity of the string.</p>
<pre><code class="language-js">
const spaceyText = '\n\t hello world!\u00a0\n\n'
spaceyText.<u>trimStart</u>()
// => 'hello world!\u00a0!\n\n'
spaceyText.<u>trimEnd</u>()
// => '\n\t hello world!'
</code></pre>
</section>
<section id="es2019-flat-flatmap">
<h2>ES2019: <code>Array</code>#<code>flat/flatMap</code></h2>
<p><code>flat(depth = 1)</code> “flattens” nested arrays up to a given depth.</p>
<pre><code class="language-js">
const data = ['Alice', ['Bob', 'Claire'], ['David', ['Erin', 'Fred'], 'Georges']]
data.<u>flat</u>() // => ['Alice', 'Bob', 'Claire', 'David', ['Erin', 'Fred'], 'Georges']
data.<u>flat</u>(2) // => ['Alice', 'Bob', 'Claire', 'David', 'Erin', 'Fred', 'Georges']
</code></pre>
<div class="fragment">
<p><code>flatMap(mapper<i>[, thisArg]</i>)</code> runs a <code>map</code> whilst flattening the result on the fly, at depth 1.</p>
<pre><code class="language-js">
const data = ['Hey 😘 wassup? 😁', 'HBD 🎂 sweetheart 💖']
const extractEmojis = (text) => text.match(/\p{Emoji}/gu)
data.map(extractEmojis) // => [['😘', '😁'], ['🎂', '💖']]
data.<u>flatMap</u>(extractEmojis) // => ['😘', '😁', '🎂', '💖']
</code></pre>
</div>
</section>
<section id="es2020">
<h1>ES2020: what’s guaranteed…</h1>
</section>
<section id="es2020-matchAll">
<h2>ES2020: <code>String</code>#<code>matchAll</code></h2>
<p>Grabs <strong>all group matches</strong> for a <em>sticky</em> or global regex.</p>
<pre><code class="language-js">
const text = 'Get in touch at tel:0983450176 or sms:478-555-1234'
text.<u>match</u>(/<u>(</u>?<protocol>[a-z]{3}<u>)</u>:<u>(</u>?<number>[\d-]+<u>)</u>/<u>g</u>)
// => ['tel:0983450176', 'sms:478-555-1234'] -- 😞 WHERE THEM GROUPS AT?!
</code></pre>
<pre class="fragment"><code class="language-js">
Array.from(text.<u>matchAll</u>(/([a-z]{3}):([\d-]+)/g)).map(
([, protocol, number]) => ({ protocol, number })
)
// => [{ number: '0983450176', protocol: 'tel' }, { number: '478-555-1234', protocol: 'sms' }]
Array.from(text.<u>matchAll</u>(/(?<protocol>[a-z]{3}):(?<number>[\d-]+)/g)).map((mr) => mr.groups)
// => [{ number: '0983450176', protocol: 'tel' }, { number: '478-555-1234', protocol: 'sms' }]
</code></pre>
<!-- Babel 7, Cr80 / FF73 / Saf 13.1 / Edge 80 = 2/2 -->
</section>
<section id="es2020-dynamic-import">
<h2>ES2020: <code>import(…)</code></h2>
<p>
Dynamically imports ES Modules (“ESM”), using promises<br/>
(incidentally, this is the heart of Webpack’s automatic code splitting)
</p>
<pre><code class="language-js">
async function evaluate(code) {
const Babel = await <u>import('@babel/standalone')</u>
return Babel.transform(code, {
ast: true,
filenameRelative: 'exercice.js',
presets: ['stage-3'],
})
}
async function loadLocale(locale) {
const locale = await <u>import(`./locales/${locale}`)</u>
LocaleManager.registerLocale(locale, { activate: true })
}
</code></pre>
</section>
<section id="es2020-bigint">
<h2>ES2020: <code>BigInt</code></h2>
<p>“Arbitrary precision” (infinite) integers (> 2<sup>53</sup>)</p>
<pre><code class="language-js">
const theBiggestInt = 9007199254740991n
const alsoHuge = BigInt(9007199254740991)
// => 9007199254740991n
const hugeButString = BigInt('9007199254740991')
// => 9007199254740991n
const bigN = 2n ** 54n
// => 18014398509481984n
[42n === 42, 42n == 42]
// => [false, true]
</code></pre>
<!-- FF68, Cr77, Node 10, Edge 79 -->
</section>
<section id="es2020-allsettled">
<h2>ES2020: <code>Promise.allSettled</code></h2>
<p>3rd promise combinator (with <code>all</code> and <code>race</code>). <code>any</code> is at stage 3.</p>
<p>The idea: doesn’t short-circuit, be it on the first rejection or fulfillment: we get all settlements for analysis.</p>
<pre><code class="language-js">
await Promise.allSettled([wait(100), wait(50), throwAfter(75)])
// => [
// { status: 'fulfilled', value: 100 },
// { status: 'fulfilled', value: 50 },
// { status: 'rejected', reason: Error: 75 at… }
// ]
</code></pre>
<!-- Babel 7 / core-js, FF71, Cr77, Saf 13, Node 12, Edge 79 -->
</section>
<section id="es2020-global">
<h2>ES2020: <code>globalThis</code></h2>
<p>
Finally a standardization of the “global object,” regardless of the environment!<br/>
(web page, frame, worker, process, Node…)
</p>
<p>Depending on context, aliases to: <code>window</code>, <code>self</code>, <code>global</code> and sometimes <code>this</code> (not to mention edge cases).</p>
<!-- Babel 7, FF68, Cr77, Saf 12, Edge 79, Node 12 -->
</section>
<section id="optional-chaining-nullish-coalescing">
<h2>ES2020: Optional chaining and <em>Nullish coalescing</em> <span class="stage" title="Stade 3">3</span></h2>
<p>To make resilient yet readable property chains.</p>
<pre><code class="language-js">
// BEFORE
user != null && user.names != null && user.names.first
user != null && user.signUp != null && user.signUp()
user != null && user.hobbies != null && user.hobbies[0]
// AFTER
user<u>?.</u>names<u>?.</u>first
user<u>?.</u>signup<u>?.()</u>
user<u>?.</u>hobbies<u>?.[0]</u>
</code></pre>
<div class="fragment">
<p>To better handle default values.</p>
<pre><code class="language-js">
// 50 only if `options.duration == null`
const duration = options.duration <u>??</u> 50
const easing = options.advanced?.easing <u>??</u> 'inOutCubic'
</code></pre>
</div>
<!-- Babel 7, FF72 (OC) and 74 (NC), Cr80, Edge 80, Saf 13.1, Node 13/flag -->
</section>
<section>
<h1>🔮 So what’s coming next? 🔮</h1>
</section>
<section id="numerical-separators">
<h2>Numeric separators <span class="stage" title="Stade 3">3</span></h2>
<p>It’s nicer when you can read it.</p>
<pre><code class="language-js">
const BILLION = 1_000_000_000 // You immediately know
const FEE_CENTS = 20_00 // Cents / centiles
const RATE = 2_90 // Ditto
const QUADS = 0b0010_1010 // “Quads” (4 bits)
const TX_VALUE = 1_234_5418 // Fixed point (4), financial
const WORDS = 0xDEAD_C0DE // “Words” (2 bytes)
</code></pre>
<!-- Babel 7, FF70, Cr75, Saf13, Edge 79, Node 12.5 -->
</section>
<section id="top-level-await">
<h2>Top-level <code>await</code> <span class="stage" title="Stade 3">3</span></h2>
<p>Until now, we could only <code>await</code> in an <code>async</code> function…</p>
<p>But this can be super-handy for module initialization, etc.</p>
<pre><code class="language-js">
import { engine, process } from './some-module.mjs'
// Might as well run these in parallel…
const engineModule = import(`./engines/${engine}.mjs`)
const data = fetch(url)
// And presto!
export const output = process((<u>await</u> engineModule).default, <u>await</u> data)
</code></pre>
<p>Already in Node REPL, Chromium DevTools console, Safari Web Inspector console.</p>
<!-- v8/flag, Webpack 5 experimental -->
</section>
<section id="class-novelties">
<h2>Class novelties <span class="stage" title="Stade 3">3</span></h2>
<p>Private methods (incl. accessors), static and instance fields (public / private)</p>
<pre><code class="language-js">
class APIClient extends Component {
// Private instance field
<u>#oauthToken =</u> null
// Public static field
<u>static propTypes</u> = {
authServer: URLPropType.isRequired,
}
// Public instance field
<u>state =</u> { authenticated: this.#oauthToken != null, loggedIn: false }
// Private instance method
<u>#shareAuthWith</u>(recipient) {
// Demands that `recipient` be an `APIClient`
recipient.#oauthToken = this.#oauthToken
}
}
</code></pre>
<!-- Priv: Babel, v8/7.9, JSC/review, XS, QuickJS -->
<!-- IC: Babel, Node 12 / v8/7.2-7.4, Fx69, Edge 79, XS, QuickJS -->
<!-- Stat: Babel, v8/7.9, Edge 79, JSC/review, XS, QuickJS -->
</section>
<section id="decorators">
<h2>Decorators <span class="stage" title="Stade 2">2</span></h2>
<p>So much nicer for AOP… ES provides the plumbing and the ecosystem provides operational decorators.</p>
<pre><code class="language-js">
class SuperWidget extends Component {
<u>@deprecate</u>
deauth() { … }
<u>@memoize('1m')</u>
userFullName() { … }
<u>@autobind</u>
logOut() {
this.#oauthToken = null
}
<u>@override</u>
render() { … }
}
</code></pre>
</section>
<section id="temporal">
<h2><code>Temporal</code> <span class="stage" title="Stade 2">2</span></h2>
<p>Aims to (beneficially) replace Moment, Luxon, data-fns, etc.</p>
<p>Immutable, nanosecond-precise, has all TZ, distinguishes absolute vs. local, explicit…</p>
<p>Great complement to <code>Intl</code> and its formatting functions.</p>
<pre><code class="language-js">
const meeting1 = Temporal.Date.from('2020-01-01')
const meeting2 = Temporal.Date.from('2020-04-01')
const time = Temporal.Time.from('10:00:00')
const timeZone = new Temporal.TimeZone('America/Montreal')
const absolute1 = timeZone.getAbsoluteFor(meeting1.withTime(time))
// => 2020-01-01T15:00:00.000Z
const absolute2 = timeZone.getAbsoluteFor(meeting2.withTime(time))
// => 2020-01-01T14:00:00.000Z
</code></pre>
<p>Check out <a href="https://www.dotconferences.com/2019/12/maggie-johnson-pint-making-time-make-sense">Maggie’s awesome talk at dotJS 2019</a>!</p>
</section>
<section id="functional-programming">
<h2>Moar functional programming <span class="stage" title="Stade 1">1</span></h2>
<p>Pipeline operator + partial application = 😍</p>
<table class="layout">
<tbody>
<tr>
<td width="50%">
<pre><code class="language-js">
// Particularly cool when we use iterators
// (lazy hence efficient)!
const result = numbers
<u>|></u> filter(<u>?</u>, (v) => v % 2 === 0)
<u>|></u> map(<u>?</u>, (v) => v + 1)
<u>|></u> slice(<u>?</u>, 0, 3)
<u>|></u> Array.from
</code></pre>
</td>
<td>
<pre><code class="language-js">
function* filter(items, predicate) {
for (const item of items) {
if (predicate(item)) {
yield item
}
}
}
</code></pre>
</td>
</tr>
</tbody>
</table>
<div class="fragment">
<p>Pattern matching! 😍</p>
<pre><code class="language-js">
const getLength = (vector) => <u>case (vector) {</u>
<u>when { x, y, z } -></u> Math.sqrt(x ** 2 + y ** 2 + z ** 2)
<u>when { x, y } -></u> Math.sqrt(x ** 2 + y ** 2)
<u>when [...etc] -></u> vector.length
<u>}</u>
</code></pre>
</div>
<!--
Pipe: Babel 7, FF58/flag
PA: Babel 7
PM: Babel 7 ongoing
-->
</section>
<section id="protocols">
<h2>Protocols <span class="stage" title="Stade 1">1</span></h2>
<p>This is even better than traits, mixins or modules… The syntax is temporarily—and intentionally—verbose.</p>
<table class="layout">
<tbody>
<tr>
<td>
<pre><code class="language-js">
<u>protocol</u> Foldable {
foldr // “Required field” (symbol)
// “Provided field” (here an accessor)
get length() { return this[<u>Foldable.foldr</u>]((m) => m + 1, 0) }
…
// On-the-fly implementation for existing host types!
<u>implemented by</u> Array {
foldr(f, acc) { … }
}
}
</code></pre>
<pre><code class="language-js">
// Later implementation
Set.prototype[Foldable.foldr] = (f, acc) => { … }
Protocol.implement(Set, Foldable)
</code></pre>
</td>
<td>
<pre><code class="language-js">
class NEList {
…
// Implementation for the current class
implements protocol Foldable {
foldr(f, acc) { … }
}
}
</code></pre>
<pre><code class="language-js">
// Inheriting (extending) protocols
protocol Mappable extends Foldable { map }
class Collection {
implements protocol Mappable {
foldr(f, acc) { … }
map(f) { … }
}
}
</code></pre>
</td>
</tr>
</tbody>
</table>
<!-- NO support anywhere for now -->
</section>
<section id="screencasts">
<h2>Do you like screencasts?</h2>
<p>We publish about one new video course every month, mostly around Git and JS.</p>
<br>
<h3><a href="https://screencasts.delicious-insights.com/">screencasts.delicious-insights.com</a></h3>
<br>
<p>Or if that’s easier for you:</p>
<br>
<h3><a href="https://bit.ly/screencasts-confoo">bit.ly/screencasts-confoo</a></h3>
</section>
<section id="thank-you">
<h1>Thank you!</h1>
<h3>Always bet on JS.</h3>
<br>
<p>Christophe Porteneuve</p>
<p><a href="https://twitter.com/porteneuve">@porteneuve</a></p>
<p class="breathing">
Slides are at <a href="https://bit.ly/confoo-es2022">bit.ly/confoo-es2022</a><br/>
</p>
<footer>h/t to Nicholas C. Zakas’ wonderful <a href="https://leanpub.com/understandinges6/">Understanding ES6</a> and Axel Rauschmayer’s excellent <a href="https://exploringjs.com/es6/">Exploring ES6</a>,<br/>
which both have great chapters on ES proxies, and provided the basis for several examples I used.</footer>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="plugin/highlight/prism.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available here: // https://github.com/hakimel/reveal.js#configuration
/* global Reveal */
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
width: '95%',
height: '90%',
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/fade/none
// 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: 'lib/js/classList.js', condition: function () { return !document.body.classList } },
{ src: 'plugin/markdown/marked.js', condition: function () { return !!document.querySelector('[data-markdown]') } },
{ src: 'plugin/markdown/markdown.js', condition: function () { return !!document.querySelector('[data-markdown]') } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function () { return !!document.body.classList } },
{ src: 'plugin/notes/notes.js', async: true, condition: function () { return !!document.body.classList } }
]
})
</script>
</body>
</html>