SlideShare a Scribd company logo
1 of 30
Download to read offline
ECMAScript 6
by Vincent Dupont
While42 meeting
8th July 2014
Plan
• Ecma International
• ECMAScript
• JavaScript
• Examples
• Conclusion
• Questions
Ecma International
• European Computer Manufacturers Association
• Founded in 1961
• Standardize computer systems
ECMASCript
• Specification ECMA-262
• Scripting “client side”
• Implementations (JavaScript, JScript, ActionScript)
JavaScript
• Brendan Eich (Netscape)
• Mocha, LiveScript
• 1995 (premiere version)
• 2009 version 5
• 2011 version 5.1
• Juin 2015 version 6
Multi paradigme
• Scripting
• Imperative
• Functional
• Oriente objet (Prototypage)
Constants
const PI = 3.141593
let
scope problems?
// ES5
var hello = 'while 42';
{
var hello = 'world';
}
console.log(hello); // return 'world'
// ES6
let world = 'while 42';
{
// let solve block scoping
let world = 'world';
}
console.log(world); // return ‘while 42'
// ES5
var fs = [];
for (var i = 0; i < 5; i++) {
fs.push(function() {
console.log(i);
})
}
fs.forEach(function(f) {
f(); // return 5
});
// ES6
fs = [];
for (let j = 0; j < 5; j++) {
fs.push(function() {
console.log(j);
})
}
fs.forEach(function(f) {
f(); // return 0 to 4
});
Arrow
// ES5
var sayHello = function (who) { console.log('hello ' + who); };
sayHello('while 42');
// ES6
var sayHello = who => console.log('hello ' + who);
sayHello('world');
var sayWhat = (say, what) => console.log(say + ' ' + what);
sayWhat('je dis', 'bonjour');
Syntactic sugar?
var oldDeliveryBoy = {
name: 'Vincent',
deliver: function(msg, handler) {
handler(msg);
},
receive: function() {
var that = this;
this.deliver('Hello ', function(msg) {
console.log(msg + that.name);
})
}
};
oldDeliveryBoy.receive();
var newDeliveryBoy = {
name: 'Vincent',
deliver: function(msg, handler) {
handler(msg);
},
receive: function() {
this.deliver('Hello ', msg => console.log(msg + this.name));
}
};
newDeliveryBoy.receive();
Default Parameter Values
function greet(firstName = 'John', lastName = 'Smith') {
console.log(firstName + ' ' + lastName);
}
greet();
greet('Paul');
var oldFnDefFnValue = function (fn = function () { console.log('complete old'); }) {
fn();
};
oldFnDefFnValue();
var newFnDefFnValue = (fn = () => console.log('complete new')) => fn();
newFnDefFnValue();
String templates
var greeting = 'world';
var template = `
hello ${greeting}
crazy ${greeting}
`;
console.log(template);
var x = 1;
var y = 2;
var equation = `${ x } + ${ y } = ${ x + y }`;
console.log(equation);
hello world
crazy world
1 + 2 = 3
var parseString = (strings, ...values) => {
console.log(strings);
console.log(values);
if (values[0] < 20) {
values[1] = 'awake';
} else {
values[1] = 'sleeping';
}
return `${strings[0]}${values[0]}${strings[1]}${values[1]}`
};
var templateResult = parseString`It's ${new Date().getHours()}, I'm ${""}`;
console.log(templateResult);
[ 'It's ', ', I'm ', '' ]
[ 21, '' ]
It's 21, I'm sleeping
Enhanced object properties
var color = 'red';
var speed = 100;
function go() {
console.log('vroom');
}
var action = 'start';
var car = {
color,
speed,
go,
horn() {
console.log('honk honk');
},
[action]: function () {
console.log('start');
}
}; // same as : var car = {color: color, speed: speed};
console.log(car.color); // return red
console.log(car.speed); // return 100
car.go(); // return vroom
car.horn(); // return honk honk
car.start(); // return start
Spread operator
console.log([1, 2, 3]); // return [1, 2, 3]
console.log(...[1, 2, 3]); // return 1 2 3
let first = [1, 2, 3];
let second = [4, 5, 6];
first.push(second);
console.log(first); // return [1, 2, 3, [4, 5, 6]]
first = [1, 2, 3];
second = [4, 5, 6];
first.push(...second);
console.log(first); // return [1, 2, 3, 4, 5, 6]
function addThreeThings(a, b, c) {
return a + b + c;
}
console.log(addThreeThings(...first)); // return 6
Destructuring assignment
var {firstName, lastName} = { // could also receive a function returning an object
firstName: 'vincent',
lastName: 'dupont'
};
console.log(firstName);
console.log(lastName);
var {firstName: prenom, lastName: nom} = { // could also receive a function returning an object
firstName: 'vincent',
lastName: 'dupont'
};
console.log(prenom);
console.log(nom);
var [one,,,last] = [1, 2, 3, 4];
console.log(one); // return 1
console.log(last); // return 4
var beatles = [
{firstName: 'John', lastName: 'Lennon'},
{firstName: 'Paul', lastName: 'McCartney'},
{firstName: 'Ringo', lastName: 'Starr'},
{firstName: 'Georges', lastName: 'Harrison'}
];
beatles.forEach(({firstName}) => console.log(firstName));
function logLastName({lastName}) { console.log(lastName); }
var [, paul] = beatles;
logLastName(paul); // return McCartney
Array comprehension
var nums = [1, 2, 3, 4, 5];
var aboveTwo = [num for(num of nums) if(num > 2)];
console.log(aboveTwo); // return [3, 4, 5]
Generators
function* gen() {
console.log(`You called 'next()'`);
yield 'hello';
console.log(`You called 'next()' again`);
yield 'world';
}
let genResult = gen();
console.log(genResult);
let next = genResult.next();
console.log(next);
let done = genResult.next();
console.log(done);
for (let output of gen()) {
console.log(output);
}
Build things through iteration process
function* gen2() {
let temp = yield 'how';
temp = yield temp + 'is';
yield temp + 'possible?';
}
let gen2result = gen2();
console.log(gen2result.next().value);
console.log(gen2result.next(' the heck ').value);
console.log(gen2result.next(' this crazy ').value);
how
the heck is
this crazy possible?
work with infinite sequence
function* seq() {
let x = 0;
let y = 0;
while (true) {
yield x + y;
x += 1;
y += 2;
}
}
var seqGen = seq();
console.log(seqGen.next().value);
console.log(seqGen.next().value);
console.log(seqGen.next().value);
Classes
// ES5
var Shape = function (id, x, y) {
this.id = id;
this.move(x, y);
};
Shape.prototype.move = function (x, y) {
this.x = x;
this.y = y;
};
// ES6
class Shape {
constructor (id, x, y) {
this.id = id
this.move(x, y)
}
move (x, y) {
this.x = x
this.y = y
}
}
Class Inheritance
// ES5
var Rectangle = function (id, x, y, width, height) {
Shape.call(this, id, x, y);
this.width = width;
this.height = height;
};
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;
var Circle = function (id, x, y, radius) {
Shape.call(this, id, x, y);
this.radius = radius;
};
Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.constructor = Circle;
// ES6
class Rectangle extends Shape {
constructor (id, x, y, width, height) {
super(id, x, y)
this.width = width
this.height = height
}
}
class Circle extends Shape {
constructor (id, x, y, radius) {
super(id, x, y)
this.radius = radius
}
}
Binary and Octal Literals
// ES6
0b111110111 === 503 // true
0o767 === 503 // true
// ES5
parseInt("111110111", 2) === 503;
parseInt("767", 8) === 503;
0767 === 503; // only in non-strict, backward compatibility mode
Meta-Programming
let target = {
foo: "Welcome, foo"
}
let proxy = new Proxy(target, {
get (receiver, name) {
return name in receiver ? receiver[name] : `Hello, ${name}`
}
})
proxy.foo === "Welcome, foo"
proxy.world === "Hello, world"
Proxy
let obj = { a: 1 }
Object.defineProperty(obj, "b", { value: 2 })
obj[Symbol("c")] = 3
Reflect.ownKeys(obj) // [ "a", "b", Symbol(c) ]
Reflection
Some more
• Typed arrays
• Promises
• Modules improvement
Conclusion
Some very good features…
but not only :)
?
References
• https://egghead.io
• https://github.com/lukehoban/es6features
• http://es6-features.org/
• https://en.wikipedia.org/wiki/ECMAScript

More Related Content

What's hot

ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generatorsRamesh Nair
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixirKent Ohashi
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ applicationDaniele Pallastrelli
 
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianBrian Lonsdorf
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021Andrzej Jóźwiak
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Evgeny Borisov
 

What's hot (20)

ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
Intro
IntroIntro
Intro
 
Javascript
JavascriptJavascript
Javascript
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
Millionways
MillionwaysMillionways
Millionways
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2
 
Pdr ppt
Pdr pptPdr ppt
Pdr ppt
 

Similar to ECMAScript 6 new features

Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxJeff Strauss
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMDdhaval10690
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
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
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 

Similar to ECMAScript 6 new features (20)

Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
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
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 

Recently uploaded

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptxAsmae Rabhi
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxgalaxypingy
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsMonica Sydney
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 

Recently uploaded (20)

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 

ECMAScript 6 new features

  • 1. ECMAScript 6 by Vincent Dupont While42 meeting 8th July 2014
  • 2. Plan • Ecma International • ECMAScript • JavaScript • Examples • Conclusion • Questions
  • 3. Ecma International • European Computer Manufacturers Association • Founded in 1961 • Standardize computer systems
  • 4. ECMASCript • Specification ECMA-262 • Scripting “client side” • Implementations (JavaScript, JScript, ActionScript)
  • 5. JavaScript • Brendan Eich (Netscape) • Mocha, LiveScript • 1995 (premiere version) • 2009 version 5 • 2011 version 5.1 • Juin 2015 version 6
  • 6. Multi paradigme • Scripting • Imperative • Functional • Oriente objet (Prototypage)
  • 8. let scope problems? // ES5 var hello = 'while 42'; { var hello = 'world'; } console.log(hello); // return 'world' // ES6 let world = 'while 42'; { // let solve block scoping let world = 'world'; } console.log(world); // return ‘while 42'
  • 9. // ES5 var fs = []; for (var i = 0; i < 5; i++) { fs.push(function() { console.log(i); }) } fs.forEach(function(f) { f(); // return 5 }); // ES6 fs = []; for (let j = 0; j < 5; j++) { fs.push(function() { console.log(j); }) } fs.forEach(function(f) { f(); // return 0 to 4 });
  • 10. Arrow // ES5 var sayHello = function (who) { console.log('hello ' + who); }; sayHello('while 42'); // ES6 var sayHello = who => console.log('hello ' + who); sayHello('world'); var sayWhat = (say, what) => console.log(say + ' ' + what); sayWhat('je dis', 'bonjour'); Syntactic sugar?
  • 11. var oldDeliveryBoy = { name: 'Vincent', deliver: function(msg, handler) { handler(msg); }, receive: function() { var that = this; this.deliver('Hello ', function(msg) { console.log(msg + that.name); }) } }; oldDeliveryBoy.receive(); var newDeliveryBoy = { name: 'Vincent', deliver: function(msg, handler) { handler(msg); }, receive: function() { this.deliver('Hello ', msg => console.log(msg + this.name)); } }; newDeliveryBoy.receive();
  • 12. Default Parameter Values function greet(firstName = 'John', lastName = 'Smith') { console.log(firstName + ' ' + lastName); } greet(); greet('Paul'); var oldFnDefFnValue = function (fn = function () { console.log('complete old'); }) { fn(); }; oldFnDefFnValue(); var newFnDefFnValue = (fn = () => console.log('complete new')) => fn(); newFnDefFnValue();
  • 13. String templates var greeting = 'world'; var template = ` hello ${greeting} crazy ${greeting} `; console.log(template); var x = 1; var y = 2; var equation = `${ x } + ${ y } = ${ x + y }`; console.log(equation); hello world crazy world 1 + 2 = 3
  • 14. var parseString = (strings, ...values) => { console.log(strings); console.log(values); if (values[0] < 20) { values[1] = 'awake'; } else { values[1] = 'sleeping'; } return `${strings[0]}${values[0]}${strings[1]}${values[1]}` }; var templateResult = parseString`It's ${new Date().getHours()}, I'm ${""}`; console.log(templateResult); [ 'It's ', ', I'm ', '' ] [ 21, '' ] It's 21, I'm sleeping
  • 15. Enhanced object properties var color = 'red'; var speed = 100; function go() { console.log('vroom'); } var action = 'start'; var car = { color, speed, go, horn() { console.log('honk honk'); }, [action]: function () { console.log('start'); } }; // same as : var car = {color: color, speed: speed}; console.log(car.color); // return red console.log(car.speed); // return 100 car.go(); // return vroom car.horn(); // return honk honk car.start(); // return start
  • 16. Spread operator console.log([1, 2, 3]); // return [1, 2, 3] console.log(...[1, 2, 3]); // return 1 2 3 let first = [1, 2, 3]; let second = [4, 5, 6]; first.push(second); console.log(first); // return [1, 2, 3, [4, 5, 6]] first = [1, 2, 3]; second = [4, 5, 6]; first.push(...second); console.log(first); // return [1, 2, 3, 4, 5, 6] function addThreeThings(a, b, c) { return a + b + c; } console.log(addThreeThings(...first)); // return 6
  • 17. Destructuring assignment var {firstName, lastName} = { // could also receive a function returning an object firstName: 'vincent', lastName: 'dupont' }; console.log(firstName); console.log(lastName); var {firstName: prenom, lastName: nom} = { // could also receive a function returning an object firstName: 'vincent', lastName: 'dupont' }; console.log(prenom); console.log(nom); var [one,,,last] = [1, 2, 3, 4]; console.log(one); // return 1 console.log(last); // return 4
  • 18. var beatles = [ {firstName: 'John', lastName: 'Lennon'}, {firstName: 'Paul', lastName: 'McCartney'}, {firstName: 'Ringo', lastName: 'Starr'}, {firstName: 'Georges', lastName: 'Harrison'} ]; beatles.forEach(({firstName}) => console.log(firstName)); function logLastName({lastName}) { console.log(lastName); } var [, paul] = beatles; logLastName(paul); // return McCartney
  • 19. Array comprehension var nums = [1, 2, 3, 4, 5]; var aboveTwo = [num for(num of nums) if(num > 2)]; console.log(aboveTwo); // return [3, 4, 5]
  • 20. Generators function* gen() { console.log(`You called 'next()'`); yield 'hello'; console.log(`You called 'next()' again`); yield 'world'; } let genResult = gen(); console.log(genResult); let next = genResult.next(); console.log(next); let done = genResult.next(); console.log(done); for (let output of gen()) { console.log(output); }
  • 21. Build things through iteration process function* gen2() { let temp = yield 'how'; temp = yield temp + 'is'; yield temp + 'possible?'; } let gen2result = gen2(); console.log(gen2result.next().value); console.log(gen2result.next(' the heck ').value); console.log(gen2result.next(' this crazy ').value); how the heck is this crazy possible?
  • 22. work with infinite sequence function* seq() { let x = 0; let y = 0; while (true) { yield x + y; x += 1; y += 2; } } var seqGen = seq(); console.log(seqGen.next().value); console.log(seqGen.next().value); console.log(seqGen.next().value);
  • 23. Classes // ES5 var Shape = function (id, x, y) { this.id = id; this.move(x, y); }; Shape.prototype.move = function (x, y) { this.x = x; this.y = y; }; // ES6 class Shape { constructor (id, x, y) { this.id = id this.move(x, y) } move (x, y) { this.x = x this.y = y } }
  • 24. Class Inheritance // ES5 var Rectangle = function (id, x, y, width, height) { Shape.call(this, id, x, y); this.width = width; this.height = height; }; Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; var Circle = function (id, x, y, radius) { Shape.call(this, id, x, y); this.radius = radius; }; Circle.prototype = Object.create(Shape.prototype); Circle.prototype.constructor = Circle; // ES6 class Rectangle extends Shape { constructor (id, x, y, width, height) { super(id, x, y) this.width = width this.height = height } } class Circle extends Shape { constructor (id, x, y, radius) { super(id, x, y) this.radius = radius } }
  • 25. Binary and Octal Literals // ES6 0b111110111 === 503 // true 0o767 === 503 // true // ES5 parseInt("111110111", 2) === 503; parseInt("767", 8) === 503; 0767 === 503; // only in non-strict, backward compatibility mode
  • 26. Meta-Programming let target = { foo: "Welcome, foo" } let proxy = new Proxy(target, { get (receiver, name) { return name in receiver ? receiver[name] : `Hello, ${name}` } }) proxy.foo === "Welcome, foo" proxy.world === "Hello, world" Proxy let obj = { a: 1 } Object.defineProperty(obj, "b", { value: 2 }) obj[Symbol("c")] = 3 Reflect.ownKeys(obj) // [ "a", "b", Symbol(c) ] Reflection
  • 27. Some more • Typed arrays • Promises • Modules improvement
  • 28. Conclusion Some very good features… but not only :)
  • 29. ?
  • 30. References • https://egghead.io • https://github.com/lukehoban/es6features • http://es6-features.org/ • https://en.wikipedia.org/wiki/ECMAScript