ECMAWat?! (Dutch)

A presentation at PFCongres in October 2016 in Utrecht, Netherlands by Jayne Mast

Slide 1

Slide 1

ECMAWat?!

Slide 2

Slide 2

Paul Verbeek

Slide 3

Slide 3

workingatbooking.com

Slide 4

Slide 4

nlhtml5.org

Slide 5

Slide 5

ECMAScript

Slide 6

Slide 6

ECMAScript ?

Slide 7

Slide 7

"ECMAScript was always an unwanted trade name that sounds like a skin disease. https://mail.mozilla.org/pipermail/es-discuss/2006-October/000133.html Brendan Eich, uitvinder van JavaScript

Slide 8

Slide 8

ECMA-262

Slide 9

Slide 9

ECMA-420 Dart programming language

Slide 10

Slide 10

ECMA-222 Adaptive Lossless Data Compression Algorithm

Slide 11

Slide 11

ECMA-74 Measurement of Airborne Noise Emitted
by Information Technology
and Telecommunications Equipment

Slide 12

Slide 12

ECMA-262 ECMAScript® Language Specification

Slide 13

Slide 13

ActionScript

Slide 14

Slide 14

Adobe ExtendScript

Slide 15

Slide 15

JScript

Slide 16

Slide 16

V8 SpiderMonkey Chakra

Slide 17

Slide 17

JavaScript

Slide 18

Slide 18

ECMA-262 6th edition The ECMAScript® 2015
Language Specification

Slide 19

Slide 19

ES6

Slide 20

Slide 20

• Arrow functions • Binary and Octal Literals • Block-scoped variables (let / const) • Classes • Default + rest + spread parameters • Destructuring • Enhanced object literals • Generators • Iterators + for..of • Map + Set + WeakMap + WeakSet ES6

Slide 21

Slide 21

• new Math, Number, String, Array, Object APIs • Modules • Promises • Proxies • Reflect API • Subclassable Built-ins • Symbols • Ta i l C a l l s • Template strings • Unicode (full support) ES6

Slide 22

Slide 22

ES2016

Slide 23

Slide 23

• Array.prototype.includes • Exponentiation Operator ES2016

Slide 24

Slide 24

Block-scoped variables

Slide 25

Slide 25

function logPaul() { 
 
 if (true) { 


var name = 'Paul Verbeek'; 
 } 
 
 console.log(name); // Paul Verbeek 
 } 
 
 logPaul();

Slide 26

Slide 26

function logPaul() { 


var name = undefined; 
 
 if (true) { 
 name = 'Paul Verbeek'; 
 } 
 
 console.log(name); // Paul Verbeek } 
 
 logPaul();

Slide 27

Slide 27

function logPaul() { 
 
 if (true) { 


let name = 'Paul Verbeek'; 
 } 
 
 console.log(name); // name is not defined 
 } 
 
 logPaul();

Slide 28

Slide 28

function logAllThePauls() { 


var pauls = ['Paul Verbeek', 
 'Paul McCartney', 
 'Paul Simon’]; 
 
 


for ( var i = 0; i < pauls.length; i++) { 
 console.log(pauls[i]); 
 } 
 
 console.log(i); // 3 
 } 
 logAllThePauls();

Slide 29

Slide 29

function logAllThePauls() { 


let pauls = ['Paul Verbeek', 
 'Paul McCartney', 
 'Paul Simon’]; 
 
 


for ( let i = 0; i < pauls.length; i++) { 
 console.log(pauls[i]); 
 } 
 
 console.log(i); // i is not defined 
 } 
 logAllThePauls();

Slide 30

Slide 30

var globalVar = 'global variable'; 
 let globalLet = 'also global'; 
 
 function f() { 


var functionVar = 'function-scoped'; 


let functionLet = 'this one too'; 
 } 
 
 f();

Slide 31

Slide 31

function logPaul() { 


let name = 'Paul Verbeek'; 


let name = 'Paul McCartney'; 


// Identifier 'name' has already been declared 
 
 console.log(name); 
 } 
 
 logPaul();

Slide 32

Slide 32

function logConstantPaul() { 


const paul = 'Paul Verbeek’; paul = 'Paul Simon'; 


// 'paul' is read-only 
 
 console.log(paul); 
 } 
 
 logConstantPaul();

Slide 33

Slide 33

function logConstantPaul() { 


const paul = { 
 firstName: 'Paul', 
 lastName: 'McCartney' 
 }; 
 
 paul = 'Verbeek'; 
 
 console.log(paul.lastName); // Verbeek 
 } 
 
 logConstantPaul();

Slide 34

Slide 34

function logConstantPaul() { 


const paul = { 
 firstName: 'Paul', 
 lastName: 'McCartney' 
 }; 
 
 paul = {}; 


// 'paul' is read-only 
 } 
 
 logConstantPaul();

Slide 35

Slide 35

Temporal Dead Zone (TDZ) TEMPORAL

Slide 36

Slide 36

console.log(typeof foo); // ReferenceError 
 console.log(typeof bar); // 'undefined' 
 
 let foo = 'inner scope’; var bar = 'inner scope’;

Slide 37

Slide 37

let foo = 'outer scope'; 
 
 ( function () { 
 console.log(typeof foo); // ReferenceError 
 


let foo = 'inner scope'; 
 }());

Slide 38

Slide 38

const? let? var? Gebruik altijd const , behalve als je variabele moet kunnen veranderen. Gebruik anders let .

Slide 39

Slide 39

Block-scoped variables

Slide 40

Slide 40

Template strings

Slide 41

Slide 41

console.log('In ECMAScript 5.1 is 
 dit een error.’); 
 // Uncaught SyntaxError: Unexpected token ILLEGAL console.log(In ES6 zal dit 
 een nieuwe regel geven.); 
 // In ES6 zal dit 
 // een nieuwe regel geven.

Slide 42

Slide 42

Een wat?

Slide 43

Slide 43

Een backtick of accent grave Dus: ` in plaats van: '

Slide 44

Slide 44

var location = 'PFCongres', 
 topic = 'ES6'; 
 
 console.log('Bij ' + location + ' over ' + topic + ' aan het praten'); 
 // Bij PFCongres over ES6 aan het praten const location = 'PFCongres', 
 topic = 'ES6'; 
 
 console.log(Bij ${location} over ${topic} aan het praten); 
 // Bij PFCongres over ES6 aan het praten

Slide 45

Slide 45

Template strings

Slide 46

Slide 46

Enhanced object literals

Slide 47

Slide 47

function getPerson(firstName, lastName, age) { 


return { 
 name: ${firstName} ${lastName} 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 
 console.log(me); 
 // {"name":"Paul Verbeek"}

Slide 48

Slide 48

function getPerson(firstName, lastName, age) { 


return { 
 name: ${firstName} ${lastName}, 
 age: age 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 
 console.log(me); 
 // {"name":"Paul Verbeek","age":29}

Slide 49

Slide 49

function getPerson(firstName, lastName, age) { 


return { 
 name: ${firstName} ${lastName}, 
 age 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 
 console.log(me); 
 // {"name":"Paul Verbeek","age":29}

Slide 50

Slide 50

function getPerson(firstName, lastName, age) { 


const name = ${firstName} ${lastName}; 


return { name, age }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 
 console.log(me); 
 // {"name":"Paul Verbeek","age":29}

Slide 51

Slide 51

function getPerson(firstName, lastName, age) {

return { 
 name: ${firstName} ${lastName}, 
 age, makeOlder: function () {

this .age++; } 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 me.makeOlder(); 
 console.log(me); 
 // {"name":"Paul Verbeek","age":30}

Slide 52

Slide 52

function getPerson(firstName, lastName, age) {

return { 
 name: ${firstName} ${lastName}, 
 age, makeOlder() {

this .age++; } 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 me.makeOlder(); 
 console.log(me); 
 // {"name":"Paul Verbeek","age":30}

Slide 53

Slide 53

function getPerson(firstName, lastName, age) { 


return { 
 name: ${firstName} ${lastName}, 
 age, makeOlder() {

this .age++; },


 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 29); 
 me.makeOlder(); 
 console.log(me); 
 // {"name":"Paul Verbeek","age":30}

Slide 54

Slide 54

function getPerson(firstName, lastName, age) { 


return { 
 name: firstName + ' ' + lastName, 
 age, 
 
 makeOlder() { 
 this.age++; 
 }, 
 ['is' + firstName]: true 
 }; 
 } 
 
 
 const me = getPerson('Paul', 'Verbeek', 30); 
 
 console.log(me.isPaul); // true

Slide 55

Slide 55

Enhanced object literals

Slide 56

Slide 56

Arrow functions ( λ expressions)

Slide 57

Slide 57

// ES5.1 
 setTimeout( function () { 
 console.log('foo'); 
 }, 100); 
 var square = function (x) { return x * x; }; // ES6 
 setTimeout(() => { 
 console.log('foo'); 
 }, 100); 
 
 const square = x => x * x;

Slide 58

Slide 58

const arr = [1, 2, 3]; 
 let square; 
 
 // ES5.1 
 square = arr.map( function (a) { return a * a; });

  1. Minder typen // ES6 
 square = arr.map(a => a * a);

Slide 59

Slide 59

// ES5.1 
 function Interface() { 


var that = this ; 


var button = document.getElementById('myButton'); 
 
 button.addEventListener('click', function () { 
 console.log('CLICK'); 
 that.handleClick(); 
 }); 
 } 
 
 Interface.prototype.handleClick = function () { ... }; 2. Niet meer ' var that=this '

Slide 60

Slide 60

// ES6 
 function Interface() { 


const button = document.getElementById('myButton'); 
 button.addEventListener('click', () => { 
 console.log('CLICK'); 


this .handleClick(); 
 }); 
 } 
 
 Interface.prototype.handleClick = function () { ... }; 2. Niet meer ' var that=this '

Slide 61

Slide 61

Arrow functions ( λ expressions)

Slide 62

Slide 62

Classes

Slide 63

Slide 63

function Person(firstName, lastName) { 
 this.firstName = firstName; 
 this.lastName = lastName; 
 } 
 
 Person.prototype.fullName = function () { 
 return this .firstName + ' ' + this .lastName; 
 }; 
 Person.prototype.toString = function () { 
 return 'Mijn naam is ' + this .fullName(); 
 }; 
 
 var me = new Person('Paul', 'Verbeek'); 
 
 console.log(me.toString()); 
 // Mijn naam is Paul Verbeek

Slide 64

Slide 64

class Person { 


constructor (firstName, lastName) { 


this .firstName = firstName; 


this .lastName = lastName; 
 } 
 


get fullName () { 


return ${ this .firstName} ${ this .lastName}; 
 } 
 
 toString () { 
 console.log(Mijn naan is ${ this .fullName}); 
 } 
 } 
 
 const me = new Person('Paul', 'Verbeek'); 
 
 console.log(me.toString()); 
 // Mijn naam is Paul Verbeek

Slide 65

Slide 65

class Person { 
 ... 
 } 
 
 class Employee extends Person { 


constructor (firstName, lastName, company) { 


super (firstName, lastName); 


this .company = company; 
 } 
 
 toString () { 


return ${ super .toString()} 
 en ik werk bij ${ this .company}; 
 } 
 } 
 
 const me = new Employee('Paul', 'Verbeek', 'Booking.com'); 
 
 console.log(me.toString()); 
 // Mijn naan is Paul Verbeek 
 // en ik werk bij Booking.com

Slide 66

Slide 66

Classes

Slide 67

Slide 67

Default, rest and spread

Slide 68

Slide 68

multiply(3); // 6 
 multiply(3, 3); // 9 function multiply(x, y) { 
 if (typeof y === "undefined") { y = 2; } 
 


return x * y; 
 }

Slide 69

Slide 69

multiply(3); // 6 
 multiply(3, 3); // 9 function multiply(x, y = 2) { 
 
 


return x * y; 
 }

Slide 70

Slide 70

addOne(3, 7, 14); // [4, 8, 15] function addOne() { 


var numbers = Array.prototype.slice.call(arguments); 


return numbers.map(function (number) { 
 return number + 1; 
 }); 
 }

Slide 71

Slide 71

addOne(3, 7, 14); // [4, 8, 15] function addOne(...numbers) { 


return numbers.map(number => number + 1); 
 }

Slide 72

Slide 72

add(6, 3, 7, 14); // [9, 13, 20] function add(addition, ...numbers) { 


return numbers.map(number => number + addition); 
 }

Slide 73

Slide 73

function myFunction(x, y, z) { 
 return x + y + z; 
 } 
 
 var args = [16, 23, 42]; 
 myFunction.apply(null, args); // 81 myFunction(...args); // 81

Slide 74

Slide 74

var middleNumbers = [15, 16]; 
 var allNumbers = [4, 8, middleNumbers, 23, 42]; // [4, 8, [15, 16], 23, 42] var allNumbers = [4, 8].concat(middleNumbers, [23, 42]); const allNumbers = [4, 8, ...middleNumbers, 23, 42]; // [4, 8, 15, 16, 23, 42]

Slide 75

Slide 75

Default, rest and spread

Slide 76

Slide 76

https://ponyfoo.com/ http://www.2ality.com/

Slide 77

Slide 77

ECMA-262 6th edition The ECMAScript® 2015
Language Specification

Slide 78

Slide 78

Waar ik het niet over heb gehad • Binary and Octal Literals • Destructuring • Generators • Iterators + for..of • Map + Set + WeakMap + WeakSet • Modules • new Math, Number, String, Array, Object APIs • Promises • Proxies • Reflect API • Subclassable Built-ins • Symbols • Ta i l C a l l s • Unicode (full support)

Slide 79

Slide 79

ECMA-262 7th edition The ECMAScript® 2016
Language Specification

Slide 80

Slide 80

ES2016

Slide 81

Slide 81

x ** y exponentiation operator (**) Math.pow(x, y); let a = 3; 
 a **= 3; 
 // a = 27

Slide 82

Slide 82

['a', 'b', 'c'].indexOf('a') >= 0; // true ['a', 'b', 'c'].indexOf('d') >= 0; // false Array.prototype.includes ['a', 'b', 'c'].includes('a'); // true 
 ['a', 'b', 'c'].includes('d'); // false ['a', 'b', NaN].includes(NaN); // true ['a', 'b', NaN].indexOf(NaN) >= 0; // false [ , , ].includes(undefined); // true [ , , ].indexOf(undefined) >= 0; // false

Slide 83

Slide 83

ES2017

Slide 84

Slide 84

• Object.values/Object.entries
• String padding • Object.getOwnPropertyDescriptors • Trailing commas in function parameter lists and calls • Async Functions ES2017

Slide 85

Slide 85

https://github.com/tc39/ecma262/

https://tc39.github.io/ecma262/

Slide 86

Slide 86

http://kangax.github.io/compat-table/esnext/

Slide 87

Slide 87

workingatbooking.com

Slide 88

Slide 88

Slide 89

Slide 89

@_paulverbeek @nlhtml5 verbeek.p@gmail.com 4815162342

Slide 90

Slide 90

Vr a g e n ?