Slide 1

Slide 1 text

JSConfUY 2015 Say my name! A deeply analysis on the modern JavaScript (ES6 - ES2015/ES7 - ES2016)

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Carnival

Slide 4

Slide 4 text

Football

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Sepultura

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

ES5 ES6 JSJavaScript ES2015 ES2016 ES7 JSCript ActionScript ECMA

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

http://github.com/es6rocks http://es6rocks.com

Slide 11

Slide 11 text

http://jsrocks.org http://github.com/JSrocksHQ

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

https://babeljs.io

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

http://kangax.github.io/compat-table/es5/ ES5 support

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

ES6 support (November 2014) http://kangax.github.io/compat-table/es6/ 70% 60% 60% 55% 55% 35% 25%

Slide 18

Slide 18 text

ES6 support (April 2015) 73% 69% 62% 45% 74% 23% 41% 20% http://kangax.github.io/compat-table/es6/

Slide 19

Slide 19 text

ES6 support http://kangax.github.io/compat-table/es6/

Slide 20

Slide 20 text

ES7 support* http://kangax.github.io/compat-table/es7 * Babel <3 ES7 => 52% (April 2015)

Slide 21

Slide 21 text

What’s the point? - Compilers - Better syntax - Features based on community needs

Slide 22

Slide 22 text

Transpilers https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-compile-to-JS

Slide 23

Slide 23 text

Transpileception https://github.com/jaydson/transpileception

Slide 24

Slide 24 text

Write ES5 code

Slide 25

Slide 25 text

xto6

Slide 26

Slide 26 text

babel

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

rapydscript

Slide 29

Slide 29 text

ES6 Basics

Slide 30

Slide 30 text

String.includes(txt, start) // String.contains(txt, start) let msg = "JS Conf UY!"; console.log(msg.includes("!")); // true console.log(msg.includes("JS")); // true console.log(msg.includes("X")); // false console.log(msg.includes("JS", 8)); // false

Slide 31

Slide 31 text

// String.startsWith(txt, start) let msg = "JS Conf UY!"; console.log(msg.startsWith("JS")); // true console.log(msg.startsWith("js")); // false console.log(msg.startsWith("C")); // false console.log(msg.startsWith("C", 3)); // true

Slide 32

Slide 32 text

// String.endsWith(txt, end) let msg = "JS Conf UY!"; console.log(msg.endsWith("!")); // true console.log(msg.endsWith("UY!")); // true console.log(msg.endsWith("Y!", 8)); // false console.log(msg.endsWith("Conf", 7)); // true

Slide 33

Slide 33 text

// String.repeat(number) console.log("x".repeat(3)); // "xxx" console.log("hello".repeat(2)); // "hellohello" console.log("abc".repeat(4)); // "abcabcabcabc"

Slide 34

Slide 34 text

// Template strings // Basic literal string creation console.log(`In JavaScript '\n' is a line-feed.`); // Multiline strings console.log(`In JavaScript this is not legal.`); // Construct a DOM query var name = "Bob", time = "today"; console.log(`Hello ${name}, how are you ${time}?`);

Slide 35

Slide 35 text

// Template strings // Basic literal string creation console.log(`In JavaScript '\n' is a line-feed.`); // Multiline strings console.log(`In JavaScript this is not legal.`); // Construct a DOM query var name = "Bob", time = "today"; console.log(`Hello ${name}, how are you ${time}?`);

Slide 36

Slide 36 text

// Template strings // Basic literal string creation console.log(`In JavaScript '\n' is a line-feed.`); // Multiline strings console.log(`In JavaScript this is not legal.`); // Construct a DOM query var name = "Bob", time = "today"; console.log(`Hello ${name}, how are you ${time}?`);

Slide 37

Slide 37 text

// Octal and Binary Literals // ECMAScript 6 var value1 = 0o71; // 57 in decimal var value2 = 0b101; // 5 in decimal Credits: Nicholas Zakas, Understanding ES6 https://github.com/nzakas/understandinges6

Slide 38

Slide 38 text

Math.acosh(x) Math.asinh(x) Math.atanh(x) Math.cbrt(x) Math.clz32(x) Math.cosh(x) Math.expm1(x) Math.fround(x) Math.log1p(x) Math.log10(x) Math.log2(x) Math.sign(x) Math.sinh(x) Math.tanh(x) Math.trunc(x) Math.hypot(...values) Math.imul(x, y)

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

// Destructuring assignment (array pattern) var m = 11, d = 29, y = 2014; let [m, d, y] = [11, 29, 2014];

Slide 41

Slide 41 text

// Destructuring assignment (object pattern) function today() { return { d: 29, m: 11, y: 2014 }; } let { m: month, y: year } = today(); // month = 11, year = 2014

Slide 42

Slide 42 text

ES6 Main features

Slide 43

Slide 43 text

// Block scope /* Let */ for (var i = 0; i < 3; i++) { let j = i * i; console.log(j); // Works } console.log(j); // Fail http://jsrocks.com/2014/08/what-you-need-to-know-about-block-scope-let/

Slide 44

Slide 44 text

Arrow functions

Slide 45

Slide 45 text

- This binding - Not newable - No arguments object - Always anonymous

Slide 46

Slide 46 text

// Single parameter arrow fn let plusOne = x => x + 1; console.log( plusOne(5) ); // 6

Slide 47

Slide 47 text

// Single parameter arrow fn let plusOne = x => x + 1; console.log( plusOne(5) ); // 6 Function

Slide 48

Slide 48 text

// Single parameter arrow fn let plusOne = x => x + 1; console.log( plusOne(5) ); // 6 Param name

Slide 49

Slide 49 text

// Single parameter arrow fn let plusOne = x => x + 1; console.log( plusOne(5) ); // 6 return

Slide 50

Slide 50 text

// n parameters arrow fn let sum = (n1, n2) => n1 + n2; console.log( sum(2,2) ); // 4

Slide 51

Slide 51 text

// Parameterless Arrow fn let conf = () => "JSConfAR"; console.log( conf() ); // JSConfAR

Slide 52

Slide 52 text

// Arrow fn with a body let doSomething = (x, y) => { // logic return true; }

Slide 53

Slide 53 text

// Classical ‘this’ issue var foo = { init: function () { setTimeout(function () { this.log(); }, 1000); }, log: function () { console.log('foooo'); } } foo.init(); //TypeError: this.log is not a function

Slide 54

Slide 54 text

// Fixing ‘this’ issue ES5 way var foo = { init : function () { setTimeout((function () { this.log(); }).bind(this), 1000); }, log : function () { console.log('foooo'); } } foo.init(); // foooo

Slide 55

Slide 55 text

// Fixing ‘this’ issue ES6 way let foo = { init : function () { setTimeout( () => this.log(), 1000 ); }, log : function () { console.log('foooo'); } }; foo.init(); // foooo

Slide 56

Slide 56 text

Classes

Slide 57

Slide 57 text

class Animal { constructor(name) { this.name = name; } breathe () { console.log( `${this.name} is breathing` ); } }

Slide 58

Slide 58 text

class Dog extends Animal { constructor(name) { super(name); } bark() { console.log(`Woof! ${this.name} is barking`); } }

Slide 59

Slide 59 text

class Cat extends Animal { constructor(name) { super(name); } meow() { console.log(`Meow! ${this.name} is meowing`); } }

Slide 60

Slide 60 text

Modules

Slide 61

Slide 61 text

// Creating modules // baz.js let baz = 'baz'; export default baz; // app.js import baz from “baz”;

Slide 62

Slide 62 text

// Creating modules // print.js let print = function (what) { return `print module - ${what}`; } export default print;

Slide 63

Slide 63 text

// Creating modules // foo.js import baz from "./baz"; console.log('From module baz >>> ', baz); let foo = 'foo'; export default foo; export let bar = 'bar'; // foo.js import { bar } from “foo”;

Slide 64

Slide 64 text

// Using modules // app.js import print from "./modules/print"; import foo, { bar } from "./modules/foo"; console.log( print('it works') ); // print module - it works console.log( print('wow') ); // print module - wow console.log( foo ); // foo console.log( bar ); // bar

Slide 65

Slide 65 text

Case study on ES7 async functions https://github.com/jaydson/es7-async

Slide 66

Slide 66 text

Old friend Ajax

Slide 67

Slide 67 text

Not so new friend, Promises

Slide 68

Slide 68 text

Fetch API

Slide 69

Slide 69 text

Parallel execution

Slide 70

Slide 70 text

New powerful friend, generators

Slide 71

Slide 71 text

The new awesome beast, async functions

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Parallel operations with async:

Slide 75

Slide 75 text

Parallel operations with async + fetch (Oh my god this is great!):

Slide 76

Slide 76 text

https://github.com/JSRocksHQ/harmonic

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

https://github.com/JSRocksHQ/slush-es20xx

Slide 81

Slide 81 text

No content