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

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
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
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
 
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
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
 
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
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...SUHANI PANDEY
 

Recently uploaded (20)

Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
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
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
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
 
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
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
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
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 

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