SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
ECMAScript 6
Drama in 5 acts
Piotr Lewandowski
20.03.2015
All temporary solutions
become final
Act 1 - Preludium
ES 4
ES 4
ES 6
ES 4
ES 6
ES 2015
Make JavaScript better
for complex application
for libraries
as target of code generators
Pave the Cowpaths
and don't break the web
Modules
Act 2
Design goals
Compact syntax
Support cyclic dependencies
Asynchronous loading
Configurable
Design goals
Compact syntax
Support cyclic dependencies
Asynchronous loading
Configurable
// lib/math.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
// app.js
import * as math from "lib/math";
math.sum(22, 20); // 42
// Default exports and named exports
import myLib from 'src/mylib';
import { function1, function2 } from 'src/mylib';
Importing
// Default exports and named exports
import myLib from 'src/mylib';
import { function1, function2 } from 'src/mylib';
Importing
// Renaming: import named1 as myNamed1
import { function1 as fn, function2 } from 'src/mylib';
// Default exports and named exports
import myLib from 'src/mylib';
import { function1, function2 } from 'src/mylib';
Importing
// Renaming: import named1 as myNamed1
import { function1 as fn, function2 } from 'src/mylib';
// Importing the module as an object
// (with one property per named export)
import * as mylib from 'src/mylib';
// Default exports and named exports
import myLib from 'src/mylib';
import { function1, function2 } from 'src/mylib';
Importing
// Renaming: import named1 as myNamed1
import { function1 as fn, function2 } from 'src/mylib';
// Importing the module as an object
// (with one property per named export)
import * as mylib from 'src/mylib';
// Only load the module, don’t import anything
import 'src/mylib';
Syntax
Act 3
Object {} enhancement
let firstName = 'Joe';
let lastName = 'Doe';
let person = {
firstName,
['last' + 'Name']: lastName,
getAge() {
return 42;
}
};
person.firstName // Joe
person.lastName // Doe
person.getAge() // 42
var firstName = 'Joe';
var lastName = 'Doe';
var person = {
firstName: firstName,
getAge: function() {
return 42;
}
};
person['last' + 'Name'] = lastName;
person.firstName // Joe
person.lastName // Doe
person.getAge() // 42
ES6 ES5
Destructuring
let [a, , b] = [1, 2, 3];
Destructuring
let [a, , b] = [1, 2, 3];
[a, b] = [b, a]
let person = {
firstName: 'Joe',
lastName: 'Doe'.
age: 42
};
let { firstName, lastName } = person;
firstName // Joe
lastName // Doe
Destructuring
let [a, , b] = [1, 2, 3];
[a, b] = [b, a]
Spread operator
Math.max(...[1, 2, 3]);
// the same as
Math.max(1, 2, 3);
Spread operator
Math.max(...[1, 2, 3]);
// the same as
Math.max(1, 2, 3);
let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
arr1.push(...arr2);
Spread operator
Math.max(...[1, 2, 3]);
// the same as
Math.max(1, 2, 3);
let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
arr1.push(...arr2);
[head, ...tail] = [1, 2, 3, 4, 5];
Scope - let & const
function foo() {
a = 1;
if (a) {
var a;
let b = a + 2;
Scope - let & const
function foo() {
a = 1;
if (a) {
var a;
let b = a + 2;
console.log( b );
}
console.log( a );
console.log( b );
}
Scope - let & const
function foo() {
a = 1;
if (a) {
var a;
let b = a + 2;
console.log( b );
}
console.log( a );
console.log( b );
}
console.log( b ); // 3
}
console.log( a ); // 1
console.log( b ); // ReferenceError: `b` is not defined
}
function foo() {
a = 1; // careful, `a` has been hoisted!
if (a) {
var a; // hoisted to function scope!
let b = a + 2; // `b` block-scoped to `if` block!
Scope - let & const
function foo() {
a = 1;
if (a) {
var a;
let b = a + 2;
console.log( b );
}
console.log( a );
console.log( b );
}
console.log( b ); // 3
}
console.log( a ); // 1
console.log( b ); // ReferenceError: `b` is not defined
}
function foo() {
a = 1; // careful, `a` has been hoisted!
if (a) {
var a; // hoisted to function scope!
let b = a + 2; // `b` block-scoped to `if` block!
if (true) {
const foo = "foo";
// error
foo = "bar";
}
Functions
Act 4
Classes
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
Classes
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
toString() {
return super.toString() + ' in ' + this.color;
}
}
Classes
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
toString() {
return super.toString() + ' in ' + this.color;
}
}
let cp = new ColorPoint(25, 8, 'green');
cp.toString(); // '(25, 8) in green'
console.log(cp instanceof ColorPoint); // true
console.log(cp instanceof Point); // true
console.log(typeof Point); // function
Arrow functions
(x, y) => x + y
Lexical scope
class Person {
constructor() {
this.name = 'Joe';
}
// ...
load() {
xhrGet(data => {
this.name = data.name;
});
}
}
function Person {
this.name = 'Joe';
// ...
this.load = function() {
var that = this;
xhrGet(function(data) {
that.name = data.name;
});
}
}
Lexical scope
vs
document.body.addEventListener('click', function(event) {
console.log(event, this) // EventObject, BodyElement
});
document.body.addEventListener('click', event =>
console.log(event, this) // EventObject, WindowElement
);
Default parameters
function add(x = 0, y = 0) {
return x + y;
}
function add(x, y) {
x = x || 0;
y = y || 0;
return x + y;
}
ES6
ES5
Rest parameter
function friends(...friends) {
friends.forEach(friend => {
// ...
}
}
function friends() {
var friends = [].slice.call(arguments, 1);
friends.forEach(function(friend) {
// ...
}
}
ES6
ES5
Can I use it?
Act 5 - Final
Compilators
TypeScript
Traceur
Babel
Compilators
TypeScript
Traceur
Babel
for back-end
Babel-node for node.js
io.js - fork of node.js
Stay tuned
and check
compatibility table
http://kangax.github.io/compat-table/es6/
Further reading
2ality.com
kangax ES6 compatibility table
babeljs.io/docs/learn-es6

Más contenido relacionado

La actualidad más candente

Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Nilesh Jayanandana
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generatorsRamesh Nair
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftGiordano Scalzo
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!Brendan Eich
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancementup2soul
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)David de Boer
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分bob_is_strange
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 

La actualidad más candente (20)

Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancement
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 

Similar a ECMAScript 6

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 
FunctionalJS - George Shevtsov
FunctionalJS - George ShevtsovFunctionalJS - George Shevtsov
FunctionalJS - George ShevtsovGeorgiy Shevtsov
 
1. George Shevtsov - Functional JavaScript
1. George Shevtsov - Functional JavaScript1. George Shevtsov - Functional JavaScript
1. George Shevtsov - Functional JavaScriptInnovecs
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfNuttavutThongjor1
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdfNuttavutThongjor1
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)David Atchley
 

Similar a ECMAScript 6 (20)

Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
recap-js.pdf
recap-js.pdfrecap-js.pdf
recap-js.pdf
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
 
FunctionalJS - George Shevtsov
FunctionalJS - George ShevtsovFunctionalJS - George Shevtsov
FunctionalJS - George Shevtsov
 
1. George Shevtsov - Functional JavaScript
1. George Shevtsov - Functional JavaScript1. George Shevtsov - Functional JavaScript
1. George Shevtsov - Functional JavaScript
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
ts+js
ts+jsts+js
ts+js
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
 
Groovy
GroovyGroovy
Groovy
 
this
thisthis
this
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 

Último

Top Rated Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated  Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...Top Rated  Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...Call Girls in Nagpur High Profile
 
Dubai Call Girls O525547&19 (Asii) Call Girls Dubai
Dubai Call Girls O525547&19 (Asii) Call Girls DubaiDubai Call Girls O525547&19 (Asii) Call Girls Dubai
Dubai Call Girls O525547&19 (Asii) Call Girls Dubaikojalkojal131
 
Supermarket Floral Ad Roundup- Week 17 2024.pdf
Supermarket Floral Ad Roundup- Week 17 2024.pdfSupermarket Floral Ad Roundup- Week 17 2024.pdf
Supermarket Floral Ad Roundup- Week 17 2024.pdfKarliNelson4
 
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779Best VIP Call Girls Noida Sector 50 Call Me: 8448380779
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779Delhi Call girls
 
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779Best VIP Call Girls Noida Sector 55 Call Me: 8448380779
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779Delhi Call girls
 
Film= Dubai Call Girls O525547819 Call Girls Dubai Whsatapp
Film= Dubai Call Girls O525547819 Call Girls Dubai WhsatappFilm= Dubai Call Girls O525547819 Call Girls Dubai Whsatapp
Film= Dubai Call Girls O525547819 Call Girls Dubai Whsatappkojalkojal131
 
The 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyThe 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyKatherineBishop4
 
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000Sapana Sha
 
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779Best VIP Call Girls Noida Sector 51 Call Me: 8448380779
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779Delhi Call girls
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka
call Now 9811711561 Cash Payment乂 Call Girls in Dwarkacall Now 9811711561 Cash Payment乂 Call Girls in Dwarka
call Now 9811711561 Cash Payment乂 Call Girls in Dwarkavikas rana
 
The 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyThe 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyTinuiti
 
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call Girl
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call GirlIndian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call Girl
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call GirlAroojKhan71
 

Último (12)

Top Rated Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated  Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...Top Rated  Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...
Top Rated Pune Call Girls Talegaon Dabhade ⟟ 6297143586 ⟟ Call Me For Genuin...
 
Dubai Call Girls O525547&19 (Asii) Call Girls Dubai
Dubai Call Girls O525547&19 (Asii) Call Girls DubaiDubai Call Girls O525547&19 (Asii) Call Girls Dubai
Dubai Call Girls O525547&19 (Asii) Call Girls Dubai
 
Supermarket Floral Ad Roundup- Week 17 2024.pdf
Supermarket Floral Ad Roundup- Week 17 2024.pdfSupermarket Floral Ad Roundup- Week 17 2024.pdf
Supermarket Floral Ad Roundup- Week 17 2024.pdf
 
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779Best VIP Call Girls Noida Sector 50 Call Me: 8448380779
Best VIP Call Girls Noida Sector 50 Call Me: 8448380779
 
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779Best VIP Call Girls Noida Sector 55 Call Me: 8448380779
Best VIP Call Girls Noida Sector 55 Call Me: 8448380779
 
Film= Dubai Call Girls O525547819 Call Girls Dubai Whsatapp
Film= Dubai Call Girls O525547819 Call Girls Dubai WhsatappFilm= Dubai Call Girls O525547819 Call Girls Dubai Whsatapp
Film= Dubai Call Girls O525547819 Call Girls Dubai Whsatapp
 
The 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyThe 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing Study
 
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000
Call Girls In Dev kunj Delhi 9654467111 Short 1500 Night 6000
 
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779Best VIP Call Girls Noida Sector 51 Call Me: 8448380779
Best VIP Call Girls Noida Sector 51 Call Me: 8448380779
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka
call Now 9811711561 Cash Payment乂 Call Girls in Dwarkacall Now 9811711561 Cash Payment乂 Call Girls in Dwarka
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka
 
The 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing StudyThe 15 Minute Breakdown: 2024 Beauty Marketing Study
The 15 Minute Breakdown: 2024 Beauty Marketing Study
 
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call Girl
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call GirlIndian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call Girl
Indian Call Girl In Dubai #$# O5634O3O18 #$# Dubai Call Girl
 

ECMAScript 6

  • 1. ECMAScript 6 Drama in 5 acts Piotr Lewandowski 20.03.2015
  • 2. All temporary solutions become final Act 1 - Preludium
  • 6. Make JavaScript better for complex application for libraries as target of code generators
  • 7. Pave the Cowpaths and don't break the web
  • 8.
  • 10. Design goals Compact syntax Support cyclic dependencies Asynchronous loading Configurable
  • 11. Design goals Compact syntax Support cyclic dependencies Asynchronous loading Configurable // lib/math.js export function sum(x, y) { return x + y; } export var pi = 3.141593; // app.js import * as math from "lib/math"; math.sum(22, 20); // 42
  • 12. // Default exports and named exports import myLib from 'src/mylib'; import { function1, function2 } from 'src/mylib'; Importing
  • 13. // Default exports and named exports import myLib from 'src/mylib'; import { function1, function2 } from 'src/mylib'; Importing // Renaming: import named1 as myNamed1 import { function1 as fn, function2 } from 'src/mylib';
  • 14. // Default exports and named exports import myLib from 'src/mylib'; import { function1, function2 } from 'src/mylib'; Importing // Renaming: import named1 as myNamed1 import { function1 as fn, function2 } from 'src/mylib'; // Importing the module as an object // (with one property per named export) import * as mylib from 'src/mylib';
  • 15. // Default exports and named exports import myLib from 'src/mylib'; import { function1, function2 } from 'src/mylib'; Importing // Renaming: import named1 as myNamed1 import { function1 as fn, function2 } from 'src/mylib'; // Importing the module as an object // (with one property per named export) import * as mylib from 'src/mylib'; // Only load the module, don’t import anything import 'src/mylib';
  • 17. Object {} enhancement let firstName = 'Joe'; let lastName = 'Doe'; let person = { firstName, ['last' + 'Name']: lastName, getAge() { return 42; } }; person.firstName // Joe person.lastName // Doe person.getAge() // 42 var firstName = 'Joe'; var lastName = 'Doe'; var person = { firstName: firstName, getAge: function() { return 42; } }; person['last' + 'Name'] = lastName; person.firstName // Joe person.lastName // Doe person.getAge() // 42 ES6 ES5
  • 18. Destructuring let [a, , b] = [1, 2, 3];
  • 19. Destructuring let [a, , b] = [1, 2, 3]; [a, b] = [b, a]
  • 20. let person = { firstName: 'Joe', lastName: 'Doe'. age: 42 }; let { firstName, lastName } = person; firstName // Joe lastName // Doe Destructuring let [a, , b] = [1, 2, 3]; [a, b] = [b, a]
  • 21. Spread operator Math.max(...[1, 2, 3]); // the same as Math.max(1, 2, 3);
  • 22. Spread operator Math.max(...[1, 2, 3]); // the same as Math.max(1, 2, 3); let arr1 = [0, 1, 2]; let arr2 = [3, 4, 5]; arr1.push(...arr2);
  • 23. Spread operator Math.max(...[1, 2, 3]); // the same as Math.max(1, 2, 3); let arr1 = [0, 1, 2]; let arr2 = [3, 4, 5]; arr1.push(...arr2); [head, ...tail] = [1, 2, 3, 4, 5];
  • 24. Scope - let & const function foo() { a = 1; if (a) { var a; let b = a + 2;
  • 25. Scope - let & const function foo() { a = 1; if (a) { var a; let b = a + 2; console.log( b ); } console.log( a ); console.log( b ); }
  • 26. Scope - let & const function foo() { a = 1; if (a) { var a; let b = a + 2; console.log( b ); } console.log( a ); console.log( b ); } console.log( b ); // 3 } console.log( a ); // 1 console.log( b ); // ReferenceError: `b` is not defined } function foo() { a = 1; // careful, `a` has been hoisted! if (a) { var a; // hoisted to function scope! let b = a + 2; // `b` block-scoped to `if` block!
  • 27. Scope - let & const function foo() { a = 1; if (a) { var a; let b = a + 2; console.log( b ); } console.log( a ); console.log( b ); } console.log( b ); // 3 } console.log( a ); // 1 console.log( b ); // ReferenceError: `b` is not defined } function foo() { a = 1; // careful, `a` has been hoisted! if (a) { var a; // hoisted to function scope! let b = a + 2; // `b` block-scoped to `if` block! if (true) { const foo = "foo"; // error foo = "bar"; }
  • 29. Classes class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } }
  • 30. Classes class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } } class ColorPoint extends Point { constructor(x, y, color) { super(x, y); this.color = color; } toString() { return super.toString() + ' in ' + this.color; } }
  • 31. Classes class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } } class ColorPoint extends Point { constructor(x, y, color) { super(x, y); this.color = color; } toString() { return super.toString() + ' in ' + this.color; } } let cp = new ColorPoint(25, 8, 'green'); cp.toString(); // '(25, 8) in green' console.log(cp instanceof ColorPoint); // true console.log(cp instanceof Point); // true console.log(typeof Point); // function
  • 33. Lexical scope class Person { constructor() { this.name = 'Joe'; } // ... load() { xhrGet(data => { this.name = data.name; }); } } function Person { this.name = 'Joe'; // ... this.load = function() { var that = this; xhrGet(function(data) { that.name = data.name; }); } }
  • 34. Lexical scope vs document.body.addEventListener('click', function(event) { console.log(event, this) // EventObject, BodyElement }); document.body.addEventListener('click', event => console.log(event, this) // EventObject, WindowElement );
  • 35. Default parameters function add(x = 0, y = 0) { return x + y; } function add(x, y) { x = x || 0; y = y || 0; return x + y; } ES6 ES5
  • 36. Rest parameter function friends(...friends) { friends.forEach(friend => { // ... } } function friends() { var friends = [].slice.call(arguments, 1); friends.forEach(function(friend) { // ... } } ES6 ES5
  • 37. Can I use it? Act 5 - Final
  • 40. Stay tuned and check compatibility table http://kangax.github.io/compat-table/es6/
  • 41.
  • 42. Further reading 2ality.com kangax ES6 compatibility table babeljs.io/docs/learn-es6