149
ECMAScript 2015 Tomasz Dziuda meet.js Łódź @ 9.VI.2015

Introduction to ECMAScript 2015

Embed Size (px)

Citation preview

Page 1: Introduction to ECMAScript 2015

ECMAScript 2015Tomasz Dziuda

meet.js Łódź @ 9.VI.2015

Page 2: Introduction to ECMAScript 2015

About me@dziudek [email protected]

http://dziudek.pl

Lead Developer @ GavickPro

Organizer of: • WordUp Łódź, • JoomlaDay Poland 2013, • WordCamp Poland 2014, • WordCamp Poland 2015

Page 3: Introduction to ECMAScript 2015

http://dziudek.github.io/dev-links/

Page 4: Introduction to ECMAScript 2015

ES2015 Today

Page 5: Introduction to ECMAScript 2015

Source: http://kangax.github.io/compat-table/es6/ screenshot from: 31/5/2015

Page 6: Introduction to ECMAScript 2015

https://babeljs.io/

Page 7: Introduction to ECMAScript 2015

ES2015 Features

Page 8: Introduction to ECMAScript 2015

Enhanced Object Literals

Page 9: Introduction to ECMAScript 2015

var car = {speed: 100,getSpeed() {return this.speed;

}}

// car.speed() => 100;

Page 10: Introduction to ECMAScript 2015

var chapter = 2;

var bookState = {[“ch” + chapter]: “Chapter ” + chapter,[“getChapter” + chapter]() {return this[“ch” + chapter];

}}

// bookState.ch2 => “Chapter 2”// bookState.getChapter2() => “Chapter 2”

Page 11: Introduction to ECMAScript 2015

Classes

Page 12: Introduction to ECMAScript 2015

class Person {constructor(name, age) {this.name = name;this.age = age

}toString() {return “Person: ” + this.name;

}}

Page 13: Introduction to ECMAScript 2015

Inheritance

Page 14: Introduction to ECMAScript 2015

class Person extends Mammal {constructor(name, age) {super();this.name = name;this.age = age

}toString() {return “Person: ” + this.name;

}}

Page 15: Introduction to ECMAScript 2015

static, get, set

Page 16: Introduction to ECMAScript 2015

class URLHelper {static hashVal() {return location.hash.replace(‘#’,’’);

}}

URLHelper.hashVal(); // http://domain.com/#top => “top”

Page 17: Introduction to ECMAScript 2015

class Person {constructor(name, age) {this._name = name;this._age = age

}get name() {return this._name;

}set name(newName) {this._name = newName;

}}

Page 18: Introduction to ECMAScript 2015

Built-ins subclassing

Page 19: Introduction to ECMAScript 2015

class MyArray extends Array {last() {return this[this.length - 1];

}}

Page 20: Introduction to ECMAScript 2015

Abstract classes

Page 21: Introduction to ECMAScript 2015

class Base {constructor () {if (new.target === Base) {throw TypeError("new of abstract class Base”);

}}

}

Page 22: Introduction to ECMAScript 2015

Modules

Page 23: Introduction to ECMAScript 2015

// file helper/linker.jsexport var separator = ‘,’;export function link (arr) {

return arr.join(separator); }

Page 24: Introduction to ECMAScript 2015

// file helper/linker.js

export {separator};

export {separator as s};

export {separator} from “linker”;

export {separator as s} from “linker”;

Page 25: Introduction to ECMAScript 2015

// file app.jsimport {separator, link} from ‘helper/linker’;

Page 26: Introduction to ECMAScript 2015

// file app.jsimport {separator, link} from ‘helper/linker’;

// file app.jsimport * as linker from ‘helper/linker’;// linker.separator / linker.link

Page 27: Introduction to ECMAScript 2015

// file app.jsimport {separator, link} from ‘helper/linker’;

// file app.jsimport * as linker from ‘helper/linker’;// linker.separator / linker.link

// file app.jsimport {separator as s} from ‘helper/linker’;

Page 28: Introduction to ECMAScript 2015

// file helper/linker.jsexport var separator = ‘,’;export default function(arr) {

return arr.join(separator); }

Page 29: Introduction to ECMAScript 2015

// file app.jsimport link from ‘helper/linker’;

Page 30: Introduction to ECMAScript 2015

// file app.jsimport link from ‘helper/linker’;

// file app.jsimport link, {separator} from ‘helper/linker’;

Page 31: Introduction to ECMAScript 2015

Template Strings

Page 32: Introduction to ECMAScript 2015

var msg = `<ul> <li>Item I</li> <li>Item II</li> <li>Item III</li> <li>Item IV</li> <li>Item V</li></ul>`;

Page 33: Introduction to ECMAScript 2015

var username = “John”;var msg = `Hello, ${username}`;// msg returns “Hello, John”

Page 34: Introduction to ECMAScript 2015

var firstname = “John”;var lastname = “ Doe”var msg = `Hello, ${firstname + lastname}`;// msg returns “Hello, John Doe”

Page 35: Introduction to ECMAScript 2015

var fName = “John”;var msg = `Hello, ${fName.toUpperCase()}`;// msg returns “Hello, JOHN”

Page 36: Introduction to ECMAScript 2015

var total = 100;var VAT = 23;var finalPrice = ‘’; // we’ll have an error without it

var msg = parseVAT`Sum: ${total} + VAT ${VAT}% = ${finalPrice}`;// "Sum: 100 + VAT 23% = 123"

Page 37: Introduction to ECMAScript 2015

function parseVAT(parts, total, VAT) { var output = "",

i = 0; while (i < parts.length) { output += parts[i++]; if (i < arguments.length) { output += arguments[i]; }

if(i === 3){ output += total * (100 + VAT) / 100.0; } } return output;}

Page 38: Introduction to ECMAScript 2015

function parseVAT(parts, total, VAT) { var output = "",

i = 0; while (i < parts.length) { output += parts[i++]; if (i < arguments.length) { output += arguments[i]; }

if(i === 3){ output += total * (100 + VAT) / 100.0; } } return output;}

Page 39: Introduction to ECMAScript 2015

function parseVAT(parts, total, VAT) { var output = "",

i = 0; while (i < parts.length) { output += parts[i++]; if (i < arguments.length) { output += arguments[i]; }

if(i === 3){ output += total * (100 + VAT) / 100.0; } } return output;}

Page 40: Introduction to ECMAScript 2015

function parseVAT(parts, total, VAT) { var output = "",

i = 0; while (i < parts.length) { output += parts[i++]; if (i < arguments.length) { output += arguments[i]; }

if(i === 3){ output += total * (100 + VAT) / 100.0; } } return output;}

Page 41: Introduction to ECMAScript 2015

http://jsperf.com/es6-string-literals-vs-string-concatenation

Page 42: Introduction to ECMAScript 2015

http://jsperf.com/es6-string-literals-vs-string-concatenation

Page 43: Introduction to ECMAScript 2015

Constants

Page 44: Introduction to ECMAScript 2015

const PI = 3.141593;

const ĘĆ = 1.858407;

var pięć = PI + ĘĆ;

Page 45: Introduction to ECMAScript 2015

const PI = 3.141593;

PI = 3.14; // not work

const person = { name: “John” };

person.name = “Adam”; // Correct - use Object.freeze

person.age = 25; // Correct - use Object.seal

Page 46: Introduction to ECMAScript 2015

const PI = 3.141593;

PI = 3.14; // not work

const person = { name: “John” };

person.name = “Adam”; // Correct - use Object.freeze

person.age = 25; // Correct - use Object.seal

Page 47: Introduction to ECMAScript 2015

const PI = 3.141593;

PI = 3.14; // not work

const person = { name: “John” };

person.name = “Adam”; // Correct - use Object.freeze

person.age = 25; // Correct - use Object.seal

Page 48: Introduction to ECMAScript 2015

Block scope

Page 49: Introduction to ECMAScript 2015

{ function test() {

return 1; }

test() === 1; // True

{ function test() {

return 2; }

test() === 2; // True }

test() === 1; // Still true}

Page 50: Introduction to ECMAScript 2015

{ function test() {

return 1; }

test() === 1; // True

{ function test() {

return 2; }

test() === 2; // True }

test() === 1; // Still true}

Page 51: Introduction to ECMAScript 2015

{ function test() {

return 1; }

test() === 1; // True

{ function test() {

return 2; }

test() === 2; // True }

test() === 1; // Still true}

Page 52: Introduction to ECMAScript 2015

{ function test() {

return 1; }

test() === 1; // True

{ function test() {

return 2; }

test() === 2; // True }

test() === 1; // Still true}

Page 53: Introduction to ECMAScript 2015

{ function test() {

return 1; }

test() === 1; // True

{ function test() {

return 2; }

test() === 2; // True }

test() === 1; // Still true}

Page 54: Introduction to ECMAScript 2015

var arr = [1,2,3];

for (let i = 0; i < arr.length; i++) { var temp = arr[i];}

console.log(i); // undefinedconsole.log(temp); // 3

Page 55: Introduction to ECMAScript 2015

let name = “John”;

let name = “Alex”; // Error

Page 56: Introduction to ECMAScript 2015

Arrow functions

Page 57: Introduction to ECMAScript 2015

function (fName, lName) {return fName + ‘ ‘ + lName;

}

Page 58: Introduction to ECMAScript 2015

(fName, lName) => fName + ‘ ‘ + lName;

Page 59: Introduction to ECMAScript 2015

[1, 2, 3].map(n => n * 2);

[1,2,3].filter(n => n % 2 === 0);

var person = () => ({name:“John”, age:25});

Page 60: Introduction to ECMAScript 2015

[1, 2, 3].map(n => n * 2);

[1,2,3].filter(n => n % 2 === 0);

var person = () => ({name:“John”, age:25});

Page 61: Introduction to ECMAScript 2015

[1, 2, 3].map(n => n * 2);

[1,2,3].filter(n => n % 2 === 0);

var person = () => ({name:“John”, age:25});

Page 62: Introduction to ECMAScript 2015

function Timer(){ this.time = 0;

setInterval(function() { this.time++; // won’t work }, 1000);}

var t = new Timer();

Page 63: Introduction to ECMAScript 2015

function Timer(){ this.time = 0; // below line will affect the time setInterval(() => this.time++, 1000);}

var t = new Timer();

Page 64: Introduction to ECMAScript 2015

fetch(url).then(response => response.json())

.then(data => console.log(data))

.catch(e => console.log(“Error!”));

Page 65: Introduction to ECMAScript 2015

Shorthand assignment

Page 66: Introduction to ECMAScript 2015

let name = “John”;

let person = {name};

// person = {name: “John”}

Page 67: Introduction to ECMAScript 2015

let name = “John”;

let person = {name};

// person = {name: “John”}

Page 68: Introduction to ECMAScript 2015

Destructuring

Page 69: Introduction to ECMAScript 2015

var x = 1;var y = 2;

[x, y] = [y, x]; // x=2, y=1

Page 70: Introduction to ECMAScript 2015

function names() {return [“John”, “Alex“];

}

var p1, p2;

[p1, p2] = names();

Page 71: Introduction to ECMAScript 2015

function names() {return [“John”, “Alex“, “Max”];

}

var p1, p2;

[p1, ,p2] = names();

Page 72: Introduction to ECMAScript 2015

var names = ["Alex", "John", "Max"];

var [p1, p2, p3] = names;

Page 73: Introduction to ECMAScript 2015

var names = {p1:“Alex”, p2:”John", p3:”Max”

};

var {p1, p2, p3} = names;

/* p1 = Alexp2 = Johnp3 = Max*/

Page 74: Introduction to ECMAScript 2015

function date({ day:d, month:m, year:y }) {return d + ‘-’ + m + ‘-’ + y;

}

date({ day: 20, month: 10, year: 1988 });

Page 75: Introduction to ECMAScript 2015

Better parameter handling

Page 76: Introduction to ECMAScript 2015

function power(x, y = 2) {return Math.pow(x, y);

}

// f(2) => 4

Page 77: Introduction to ECMAScript 2015

function names(x, ...y) {return 1 + y.length;

}

// names(“Alex”, “John”, “Max”) => 3

Page 78: Introduction to ECMAScript 2015

function names(x, y, z) {return x + “ ” + y + “ ” + z;

}

names(…[“Alex”, “John”, “Max”]);

Page 79: Introduction to ECMAScript 2015

var a = [3,4,5];

var b = [1,2, …a];

// b => [1,2,3,4,5]

Page 80: Introduction to ECMAScript 2015

Symbols

Page 81: Introduction to ECMAScript 2015

let symbol1 = Symbol(“test”);let symbol2 = Symbol(“test”);

symbol1 === symbol2 // False

Page 82: Introduction to ECMAScript 2015

let objWithSymbol = {[Symbol(“year”)]: 2015

}

console.log(objWithSymbol); // {}

Page 83: Introduction to ECMAScript 2015

let objWithSymbol = {[Symbol(“year”)]: 2015

}

console.log(objWithSymbol); // {}

Object.getOwnPropertySymbols(objWithSymbol);// [Symbol(year)]

Page 84: Introduction to ECMAScript 2015

Iterators & Generators

Page 85: Introduction to ECMAScript 2015

let iterable = “abc”[Symbol.iterator]();

iterable.next(); // { value: “a”, done: false }iterable.next(); // { value: “b”, done: false }iterable.next(); // { value: “c”, done: false }iterable.next(); // { value: undefined, done: true }

Page 86: Introduction to ECMAScript 2015

Iterable• Array

• String

• Map

• Set

• arguments

• DOM queries

Page 87: Introduction to ECMAScript 2015

for .. of

Page 88: Introduction to ECMAScript 2015

for(let div of document.querySelectorAll('div')) { div.style.border = "1px solid red";}

Page 89: Introduction to ECMAScript 2015

var obj = { items: [1,2,3,4,5], [Symbol.iterator]() { let i = 0; let self = this; return { next() { return { done: (i >= self.items.length), value: self.items[i++] } } } }}

Page 90: Introduction to ECMAScript 2015

for(let n of obj) {console.log(n);

}// 1// 2// 3// 4// 5

Page 91: Introduction to ECMAScript 2015

function* gen(start, stop) {while(start <= stop) {yield start;start++;

}}

Page 92: Introduction to ECMAScript 2015

var r = gen(0, 2);

r.next(); // {value: 0, done: false}r.next(); // {value: 1, done: false}r.next(); // {value: 2, done: false}r.next(); // {value: undefined, done: true}

Page 93: Introduction to ECMAScript 2015

function* gen() {yield ‘start’;yield ‘middle’;yield ‘stop’;

}

var g = gen();

g.next(); // { value: ‘start’, done: false}g.next(); // { value: ‘middle’, done: false}g.next(); // { value: ‘stop’, done: false}

Page 94: Introduction to ECMAScript 2015

function* odd(max) {for(var i = 0; i <= max; i++) {if(i % 2) yield i;

}}

let odds = […odd(20)]// [1,3,5,7,9,11,13,15,17,19]

Page 95: Introduction to ECMAScript 2015

function* odd(max) {for(var i = 0; i <= max; i++) {if(i % 2) yield i;

}}

let odds = […odd(20)]// odds = [1,3,5,7,9,11,13,15,17,19]

Page 96: Introduction to ECMAScript 2015

let odds = [];

for (let n of odd(20)) { odds.push(n);}

// odds = [1,3,5,7,9,11,13,15,17,19]

Page 97: Introduction to ECMAScript 2015

Promises

Page 98: Introduction to ECMAScript 2015

Promise states

• pending === !fulfilled && !rejected

• fulfilled === success

• rejected === fail

Page 99: Introduction to ECMAScript 2015

function readFile(filename) {return new Promise(function(fulfill, reject) {

fs.readFile(filename, encoding, function(err, res) {if(err) reject(err);else fulfill(res);

});});

}

Page 100: Introduction to ECMAScript 2015

function readFile(filename) {return new Promise(function(fulfill, reject) {

fs.readFile(filename, encoding, function(err, res) {if(err) reject(err);else fulfill(res);

});});

}

Page 101: Introduction to ECMAScript 2015

function readFile(filename) {return new Promise(function(fulfill, reject) {

fs.readFile(filename, encoding, function(err, res) {if(err) reject(err);else fulfill(res);

});});

}

Page 102: Introduction to ECMAScript 2015

function readFile(filename) {return new Promise(function(fulfill, reject) {

fs.readFile(filename, encoding, function(err, res) {if(err) reject(err);else fulfill(res);

});});

}

Page 103: Introduction to ECMAScript 2015

readFile(‘data.json’, 'utf8').then(function (res){ return JSON.parse(res);});

Page 104: Introduction to ECMAScript 2015

readFile(‘data.json’, 'utf8').then(function (res){ return JSON.parse(res);});

Page 105: Introduction to ECMAScript 2015

readFile(‘data.json’, 'utf8').then(function (res){ return JSON.parse(res);}, function (err) {

console.log(err);});

Page 106: Introduction to ECMAScript 2015

readFile(‘data.json’, 'utf8').then(function (res){ return JSON.parse(res);}).catch(function(err) {

console.log(err);});

Page 107: Introduction to ECMAScript 2015

Promise.all([ readFile(‘data1.json’, 'utf8'), readFile(‘data2.json’, 'utf8'), readFile(‘data3.json’, 'utf8')]).then((data) => { let [ f1, f2, f3 ] = data;});

Page 108: Introduction to ECMAScript 2015

Promise.all([ readFile(‘data1.json’, 'utf8'), readFile(‘data2.json’, 'utf8'), readFile(‘data3.json’, 'utf8')]).then((data) => { let [ f1, f2, f3 ] = data;});

Page 109: Introduction to ECMAScript 2015

Promise.all([ readFile(‘data1.json’, 'utf8'), readFile(‘data2.json’, 'utf8'), readFile(‘data3.json’, 'utf8')]).then((data) => { let [ f1, f2, f3 ] = data;});

Page 110: Introduction to ECMAScript 2015

Promise.race([ readFile(‘data1.json’, 'utf8'), readFile(‘data2.json’, 'utf8'), readFile(‘data3.json’, 'utf8')]).then((data) => { let fastest = data;});

Page 111: Introduction to ECMAScript 2015

Proxies

Page 112: Introduction to ECMAScript 2015

var obj = {};

var observed = new Proxy(obj, { set(target, key, value, receiver) { console.log(key+'='+value); target[key] = value; }});

observed.x = 10; // x = 10

Page 113: Introduction to ECMAScript 2015

var obj = {};

var observed = new Proxy(obj, { set(target, key, value, receiver) { console.log(key+'='+value); target[key] = value; }});

observed.x = 10; // x = 10

Page 114: Introduction to ECMAScript 2015

var obj = {};

var observed = new Proxy(obj, { set(target, key, value, receiver) { console.log(key+'='+value); target[key] = value; }});

observed.x = 10; // x = 10

Page 115: Introduction to ECMAScript 2015

var obj = {};

var observed = new Proxy(obj, { set(target, key, value, receiver) { console.log(key+'='+value); target[key] = value; }});

observed.x = 10; // x = 10

Page 116: Introduction to ECMAScript 2015

var obj = {};

var observed = new Proxy(obj, { set(target, key, value, receiver) { console.log(key+'='+value); target[key] = value; }});

observed.x = 10; // x = 10

Page 117: Introduction to ECMAScript 2015

Maps & Sets

Page 118: Introduction to ECMAScript 2015

Set

• Used to store unique values

• Iterable

• Easily accessible size

Page 119: Introduction to ECMAScript 2015

var names = new Set();

names.add(“Doe”);names.add(“Johnson”);

names.has(“Doe”); // truenames.size; // 2

names.delete(“Johnson”); // truenames.size; // 1

Page 120: Introduction to ECMAScript 2015

var names = new Set();

names.add(“Doe”);names.add(“Johnson”);

names.has(“Doe”); // truenames.size; // 2

names.delete(“Johnson”); // truenames.size; // 1

Page 121: Introduction to ECMAScript 2015

var names = new Set();

names.add(“Doe”);names.add(“Johnson”);

names.has(“Doe”); // truenames.size; // 2

names.delete(“Johnson”); // truenames.size; // 1

Page 122: Introduction to ECMAScript 2015

var names = new Set();

names.add(“Doe”);names.add(“Johnson”);

names.has(“Doe”); // truenames.size; // 2

names.delete(“Johnson”); // truenames.size; // 1

Page 123: Introduction to ECMAScript 2015

var names = new Set();

names.add(“Doe”);names.add(“Johnson”);

names.has(“Doe”); // truenames.size; // 2

names.delete(“Johnson”); // truenames.size; // 1

Page 124: Introduction to ECMAScript 2015

for (let name of names) {console.log(name);

}

let nameArr = […names];

for (let name of names.keys()) {console.log(name);

}// names.keys() === names.values()

Page 125: Introduction to ECMAScript 2015

for (let name of names) {console.log(name);

}

let nameArr = […names];

for (let name of names.keys()) {console.log(name);

}// names.keys() === names.values()

Page 126: Introduction to ECMAScript 2015

for (let name of names) {console.log(name);

}

let nameArr = […names];

for (let name of names.keys()) {console.log(name);

}// names.keys() === names.values()

Page 127: Introduction to ECMAScript 2015

Map

• Used to store values connected with unique keys

• Iterable

• Easily accessible size

• key can be primitive, object or even function

Page 128: Introduction to ECMAScript 2015

var relations = new Map();

relations.set(“John”, “Mary”);relations.set(“Adam”, “Eve”);

relations.size; // 2relations.get(“Adam”); // “Eve”relations.delete(“Adam”); // truerelations.size; // 1

Page 129: Introduction to ECMAScript 2015

var relations = new Map();

relations.set(“John”, “Mary”);relations.set(“Adam”, “Eve”);

relations.size; // 2relations.get(“Adam”); // “Eve”relations.delete(“Adam”); // truerelations.size; // 1

Page 130: Introduction to ECMAScript 2015

var relations = new Map();

relations.set(“John”, “Mary”);relations.set(“Adam”, “Eve”);

relations.size; // 2relations.get(“Adam”); // “Eve”relations.delete(“Adam”); // truerelations.size; // 1

Page 131: Introduction to ECMAScript 2015

var relations = new Map();

relations.set(“John”, “Mary”);relations.set(“Adam”, “Eve”);

relations.size; // 2relations.get(“Adam”); // “Eve”relations.delete(“Adam”); // truerelations.size; // 1

Page 132: Introduction to ECMAScript 2015

var relations = new Map();

relations.set(“John”, “Mary”);relations.set(“Adam”, “Eve”);

relations.size; // 2relations.get(“Adam”); // “Eve”relations.delete(“Adam”); // truerelations.size; // 1

Page 133: Introduction to ECMAScript 2015

for (let [key, value] of relations) {console.log(key + “ & ” + value);

}

for (let [key, value] of relations.entries()) {console.log(key + “ & ” + value);

}

for (let key of relations.keys()) {console.log(key);

}

Page 134: Introduction to ECMAScript 2015

WeakMap vs. Map

• Doesn’t prevent GC

• no information about size

• Key can be only an object (function is object too)

Page 135: Introduction to ECMAScript 2015

let privateData = new WeakMap();

class MyClass { constructor(name, age) { privateData.set(this, { name: name, age: age }); }

getName() { return privateData.get(this).name; }

getAge() { return privateData.get(this).age; }}

Page 136: Introduction to ECMAScript 2015

let privateData = new WeakMap();

class Person { constructor(name, age) { privateData.set(this, { name: name, age: age }); }

getName() { return privateData.get(this).name; }

getAge() { return privateData.get(this).age; }}

Page 137: Introduction to ECMAScript 2015

let privateData = new WeakMap();

class Person { constructor(name, age) { privateData.set(this, { name: name, age: age }); }

getName() { return privateData.get(this).name; }

getAge() { return privateData.get(this).age; }}

Page 138: Introduction to ECMAScript 2015

let privateData = new WeakMap();

class Person { constructor(name, age) { privateData.set(this, { name: name, age: age }); }

getName() { return privateData.get(this).name; }

getAge() { return privateData.get(this).age; }}

Page 139: Introduction to ECMAScript 2015

// Without WeakMaplet p1 = new Person(“John”, 25);let p2 = new Person(“Adam”, 40);privateData.size; // 2

p1 = null;privateData.size; // 2

Page 140: Introduction to ECMAScript 2015

// Without WeakMaplet p1 = new Person(“John”, 25);let p2 = new Person(“Adam”, 40);privateData.size; // 2

p1 = null;privateData.size; // 2

Page 141: Introduction to ECMAScript 2015

WeakSet vs. Set• Doesn’t prevent GC

• non-iterable

• non-accessible element values

• no information about size

• key can be only an object

Page 142: Introduction to ECMAScript 2015

Built-in Methods

Page 143: Introduction to ECMAScript 2015

[1, 5, 3, 8].find(x => x > 2); // 5

“- ”.repeat(3); // “- - - ”

Object.assign(obj, {“a”: 1}, {“b”: 2});// obj = {“a”: 1, “b”: 2}

Math.sign(25); // 1Math.sign(0); // 0

Math.sign(-25); // -1

Page 144: Introduction to ECMAScript 2015

[1, 5, 3, 8].find(x => x > 2); // 5

“- ”.repeat(3); // “- - - ”

Object.assign(obj, {“a”: 1}, {“b”: 2});// obj = {“a”: 1, “b”: 2}

Math.sign(25); // 1Math.sign(0); // 0

Math.sign(-25); // -1

Page 145: Introduction to ECMAScript 2015

[1, 5, 3, 8].find(x => x > 2); // 5

“- ”.repeat(3); // “- - - ”

Object.assign(obj, {“a”: 1}, {“b”: 2});// obj = {“a”: 1, “b”: 2}

Math.sign(25); // 1Math.sign(0); // 0

Math.sign(-25); // -1

Page 146: Introduction to ECMAScript 2015

[1, 5, 3, 8].find(x => x > 2); // 5

“- ”.repeat(3); // “- - - ”

Object.assign(obj, {“a”: 1}, {“b”: 2});// obj = {“a”: 1, “b”: 2}

Math.sign(25); // 1Math.sign(0); // 0

Math.sign(-25); // -1

Page 147: Introduction to ECMAScript 2015

… and much more

Page 148: Introduction to ECMAScript 2015

https://github.com/lukehoban/es6features#math--number--string--array--object-apis

Page 149: Introduction to ECMAScript 2015

Useful links• http://www.2ality.com/2015/02/es6-classes-final.html

• http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html

• http://kangax.github.io/compat-table/es6/

• https://github.com/lukehoban/es6features

• http://es6-features.org/

• http://ilikekillnerds.com/2015/02/what-are-weakmaps-in-es6/