SlideShare a Scribd company logo
1 of 19
Download to read offline
Carlos Blé
@carlosble
Thanks to the help provided by my colleague…
Alfredo Casado!
ES6 Simplified
Why ES6? (Also known as ES2015)
➔ Is the standard since June 2015!
➔ Gets rid of common and annoying gotchas
➔ Preserves all the good parts
➔ Syntactic sugar improves readability
➔ Powerful tools and libraries
➔ ES5 is still deployed into production
@carlosble
Simplicity
➔ Among all ES6 features we favor those that are
powerful yet simple. We like simple code:
◆ Pass all tests
◆ Clear, expressive & consistent
◆ Duplicates no behavior
◆ Small - Minimal methods & modules
Kent Beck
It’s all about the context!
Developing applications is not like
developing a library or a framework
Cost of understanding/maintaining code
VS
Cost of changing client code
Adapt your practices to the context
@carlosble
Power lies in the functions
@carlosble
1 export default {add, subtract};
2 // export default {add: add,
subtract: subtract};
3
4 function add(a + b){…}
5 function subtract(a + b){…}
Usage:
import calculator from ‘./m.js’;
calculator.add(1,1);
Modules (singletons):
1 export default {calculator};
2 // export default {calculator:
calculator};
3 function calculator(){
4 return {add, subtract};
5 }
6 function add(a + b){…}
7 function subtract(a + b){…}
Usage:
import buildCalculator from ‘./f.js’
let calculator = buildCalculator();
calculator.add(1,1);
Factory functions:
No need for IIFE anymore!
Do you really need to save memory?
Syntactic sugar for prototypes
class Person {
constructor(name) {
this.name = name;
}
hello() {
return `hi ${this.name}`;
}
}
function Person(name) {
this.name = name;
}
Person.prototype.hello = function()
return "hi " + this.name;
}
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
Warning: We avoid classes as much as we can
@carlosble
Aur revoir var!
@carlosble
1
2
3
4
5
6
7
8
9
10
11
Welcome let & const
function useLetInstead(){
const items = ['cat','dog'];
const len = items.length;
const f = [];
for (let i = 0; i < len-1; i++){
f.push(() => items[i]);
}
console.log(f[0]());
}
useLetInstead();
function doNotUseVar(){
var items = ['cat','dog'];
var len = items.length;
var f = [];
for (var i = 0; i < len-1; i++){
f.push(function(){
return items[i];
});
}
console.log(f[0]());
}
doNotUseVar();
1
2
3
4
5
6
7
8
9
10
11
Destructuring
const book = {
"author": {
"name": "Bob Sponge",
"email": "bob@gmail.com"
},
"title": "Under the sea",
"other": "stuff"
}
let {author: {name,email}, title} = book
console.log(name); // “Bob Sponge”
console.log(email); // “bob@gmail.com”
console.log(title); // “Under the sea”
var name = book.author.name;
var email = book.author.email;
var title = book.title;
console.log(name); // “Bob Sponge”
@carlosble
Simulating named parameters
function errorMessage({
message,
width = 300,
height = 300,
icon = ‘error.png’}){
...
}
function errorMessage(options){
options = options || {};
var width = options.width || 300;
var height = options.end || 300;
var icon = options.icon || ‘error.png’;
...
}
1
2
3
4
5
6
7
1
2
3
4
5
6
7
errorMessage({ message: ‘Ups! sorry’, icon: ‘other-icon.png’});
@carlosble
Destructuring + default values
function sum({x = 0, y = 0} = {}){
return x + y;
}
function destruct({a: {x}, b = 1}){
return x + b;
}
sum({x:5});
sum();
destruct();
destruct({a:{x:1}, b: 5});
destruct({a:{x:1}});
destruct({b:1});
1
2
3
4
5
6
7
8
9
10
11
12
13
@carlosble
Simulating mandatory parameters
function mandatory() {
throw new Error('Missing parameter');
}
function foo(mustBeProvided = mandatory()) {
return mustBeProvided;
}
function foo(mustBeProvided) {
if (arguments.length < 1) throw ...
if (mustBeProvided === undefined) ...
}
1
2
3
4
5
6
7
1
2
3
4
@carlosble
Rest operator
function calculate(multiplier, ...numbers) {
let sum = numbers.reduce(
(accumulator, num) => accumulator + num
);
return multiplier * sum;
}
function calculate() {
var numbers = Array.prototype.slice.call(arguments)
var multiplier = numbers.shift()
var sum = numbers.reduce(
function(accumulator, num){ return accumulator + num;}
)
return multiplier * sum;
}
1
2
3
4
5
6
1
2
3
4
5
6
7
8
@carlosble
Promises
function sendFeedback(customer, phone, answers) {
const promises = [];
for (let answer of answers) {
promises.push(new Promise((resolve) => {
answer.send(customer, phone, resolve);
}));
}
return promises;
}
const promises = sendFeedback(customer, phone, answers);
Promise.all(promises).then(() => showSuccessMessage());
1
2
3
4
5
6
7
8
9
10
11
12
@carlosble
Babel
@carlosble
Tools
➔ Gulp (workflow automation)
➔ Babel (compile to ES5)
➔ Browserify (require in the browser)
➔ ESLint (linter)
➔ Karma (test runner)
➔ Nodemon (manage node servers)
➔ Jasmine (unit tests)
➔ PhantomJs (unit & integration tests)
➔ Nightwatch (end2end tests)
@carlosble
Good stuff & References
@carlosble
★ ES6 Katas
http://es6katas.org/
★ Tests end2end con Nightwatch [es] http://miguelviera.com/blog/testing-e2e-con-
nightwatch-js-y-browserstack/
★ Tests de integracion: Gulp+Karma+Jasmine+Nodemon [es]
http://miguelviera.com/blog/integration-tests-con-gulp-karma-jasmine-phantomjs-y-nodemon/
★ Writing a Gulpfile [en]
http://www.carlosble.com/2015/09/es6-browserify-babel-gulp-jasmine/
★ How to fix de ES6 class keyword [en] https://medium.com/javascript-scene/how-to-fix-the-
es6-class-keyword-2d42bb3f4caf#.x4qojp84n
★ Let and Const [en]
https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75#.pliox5rso
★ Let and Const in Depth [en]
https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/
Books! read books!
@carlosble
● Implementation Patterns - Kent Beck
● JavaScript Allongé - Reginald Braithwaite
● JavaScript The Good Parts - Douglas Crockford
● 4 Rules of Simple Design - Corey Haines
More books: http://www.carlosble.
com/2011/02/books-you-should-read/
Bonus Track
Do you really need inheritance?
@carlosble
1
2
3
4
5
6
7
8
9
10
Template method implemented with functional inheritance:
function childClazz(){
const self = baseClazz({
compute: () => 3
});
return self;
}
console.log(
childClazz().template());
function baseClazz(methods = {}){
let compute = () => 2;
compute = methods.compute ||
compute;
return {
template : () => compute() + 1
};
}
console.log(
baseClazz().template());
1
2
3
4
5
6
7
8
9

More Related Content

What's hot

Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Nilesh Jayanandana
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node jsThomas Roch
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programmingnewmedio
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Functionxxbeta
 
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
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Dhaval Dalal
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...dantleech
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programmingAssaf Gannon
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mochaRevath S Kumar
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive? Tomasz Kowalczewski
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginnersMarcin Rogacki
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 

What's hot (19)

Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Function
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 

Viewers also liked

Top 6 DIY Accounting Software Pt. 1
Top 6 DIY Accounting Software Pt. 1Top 6 DIY Accounting Software Pt. 1
Top 6 DIY Accounting Software Pt. 1Kewho Min, CPA
 
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรี
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรีT-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรี
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรีAuraphin Phetraksa
 
Manager as strategist how to prepare a business pitch
Manager as strategist how to prepare a business pitchManager as strategist how to prepare a business pitch
Manager as strategist how to prepare a business pitchLearningade
 
METT CATSPA
METT CATSPAMETT CATSPA
METT CATSPAyah2527
 
พืชต่างถิ่น อช.เขาใหญ่
พืชต่างถิ่น อช.เขาใหญ่พืชต่างถิ่น อช.เขาใหญ่
พืชต่างถิ่น อช.เขาใหญ่Auraphin Phetraksa
 
Proactividad y Asertividad en Comunicación.
Proactividad y Asertividad en Comunicación.Proactividad y Asertividad en Comunicación.
Proactividad y Asertividad en Comunicación.Stephanie Pinzón
 
7 Reasons Why Reading is Important for Children and Adults
7 Reasons Why Reading is Important for Children and Adults7 Reasons Why Reading is Important for Children and Adults
7 Reasons Why Reading is Important for Children and AdultsTim Green
 
Brand Identity and Ireland
Brand Identity and IrelandBrand Identity and Ireland
Brand Identity and IrelandEoghan Nolan
 
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15The Top 8 Digital Trends for 2015 - Digiday Digital Love 15
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15Mike Corak
 
Ethics Issues At Enron
Ethics Issues At EnronEthics Issues At Enron
Ethics Issues At Enronsaurabh
 
ぼんやりした大人が趣味でプログラミングを始めたら
ぼんやりした大人が趣味でプログラミングを始めたらぼんやりした大人が趣味でプログラミングを始めたら
ぼんやりした大人が趣味でプログラミングを始めたらHiroaki KADOMATSU
 

Viewers also liked (15)

Top 6 DIY Accounting Software Pt. 1
Top 6 DIY Accounting Software Pt. 1Top 6 DIY Accounting Software Pt. 1
Top 6 DIY Accounting Software Pt. 1
 
Social media puzzle Presentation
Social media puzzle Presentation Social media puzzle Presentation
Social media puzzle Presentation
 
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรี
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรีT-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรี
T-FERN ศูนย์นวัตกรรมอุทยานแห่งชาติและพื้นที่คุ้มครอง จังหวัดเพชรบุรี
 
Manager as strategist how to prepare a business pitch
Manager as strategist how to prepare a business pitchManager as strategist how to prepare a business pitch
Manager as strategist how to prepare a business pitch
 
METT CATSPA
METT CATSPAMETT CATSPA
METT CATSPA
 
Tap the power of your mind
Tap the power of your mindTap the power of your mind
Tap the power of your mind
 
พืชต่างถิ่น อช.เขาใหญ่
พืชต่างถิ่น อช.เขาใหญ่พืชต่างถิ่น อช.เขาใหญ่
พืชต่างถิ่น อช.เขาใหญ่
 
Proactividad y Asertividad en Comunicación.
Proactividad y Asertividad en Comunicación.Proactividad y Asertividad en Comunicación.
Proactividad y Asertividad en Comunicación.
 
7 Reasons Why Reading is Important for Children and Adults
7 Reasons Why Reading is Important for Children and Adults7 Reasons Why Reading is Important for Children and Adults
7 Reasons Why Reading is Important for Children and Adults
 
The search for happiness
The search for happinessThe search for happiness
The search for happiness
 
Brand Identity and Ireland
Brand Identity and IrelandBrand Identity and Ireland
Brand Identity and Ireland
 
Dilatacion
DilatacionDilatacion
Dilatacion
 
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15The Top 8 Digital Trends for 2015 - Digiday Digital Love 15
The Top 8 Digital Trends for 2015 - Digiday Digital Love 15
 
Ethics Issues At Enron
Ethics Issues At EnronEthics Issues At Enron
Ethics Issues At Enron
 
ぼんやりした大人が趣味でプログラミングを始めたら
ぼんやりした大人が趣味でプログラミングを始めたらぼんやりした大人が趣味でプログラミングを始めたら
ぼんやりした大人が趣味でプログラミングを始めたら
 

Similar to ES6 Simplified

ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowKrzysztof Szafranek
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()Miłosz Sobczak
 
OPL best practices - Doing more with less easier
OPL best practices - Doing more with less easierOPL best practices - Doing more with less easier
OPL best practices - Doing more with less easierAlex Fleischer
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsMatthew Beale
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
The Beautiful Simplicity of ES2015
The Beautiful Simplicity of ES2015The Beautiful Simplicity of ES2015
The Beautiful Simplicity of ES2015Brandon Belvin
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)Tomomi Imura
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)David Atchley
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Workshop JavaScript ES6+
Workshop JavaScript ES6+Workshop JavaScript ES6+
Workshop JavaScript ES6+Roy Derks
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivitynklmish
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 

Similar to ES6 Simplified (20)

Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. Now
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()
 
OPL best practices - Doing more with less easier
OPL best practices - Doing more with less easierOPL best practices - Doing more with less easier
OPL best practices - Doing more with less easier
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
The Beautiful Simplicity of ES2015
The Beautiful Simplicity of ES2015The Beautiful Simplicity of ES2015
The Beautiful Simplicity of ES2015
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Workshop JavaScript ES6+
Workshop JavaScript ES6+Workshop JavaScript ES6+
Workshop JavaScript ES6+
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 

More from Carlos Ble

Gestión de proyectos
Gestión de proyectosGestión de proyectos
Gestión de proyectosCarlos Ble
 
Maintainable software
Maintainable softwareMaintainable software
Maintainable softwareCarlos Ble
 
Carbon offsetting
Carbon offsettingCarbon offsetting
Carbon offsettingCarlos Ble
 
BDD - Test Academy Barcelona 2017
BDD - Test Academy Barcelona 2017BDD - Test Academy Barcelona 2017
BDD - Test Academy Barcelona 2017Carlos Ble
 
Distinguir entre Problema y Solución
Distinguir entre Problema y SoluciónDistinguir entre Problema y Solución
Distinguir entre Problema y SoluciónCarlos Ble
 
Behavior Driven Development - Material de clase PMA
Behavior Driven Development - Material de clase PMABehavior Driven Development - Material de clase PMA
Behavior Driven Development - Material de clase PMACarlos Ble
 
Apuntes #XPweek
Apuntes #XPweekApuntes #XPweek
Apuntes #XPweekCarlos Ble
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and DjangoCarlos Ble
 
Charla Tdd Uji 032010
Charla Tdd Uji 032010Charla Tdd Uji 032010
Charla Tdd Uji 032010Carlos Ble
 

More from Carlos Ble (9)

Gestión de proyectos
Gestión de proyectosGestión de proyectos
Gestión de proyectos
 
Maintainable software
Maintainable softwareMaintainable software
Maintainable software
 
Carbon offsetting
Carbon offsettingCarbon offsetting
Carbon offsetting
 
BDD - Test Academy Barcelona 2017
BDD - Test Academy Barcelona 2017BDD - Test Academy Barcelona 2017
BDD - Test Academy Barcelona 2017
 
Distinguir entre Problema y Solución
Distinguir entre Problema y SoluciónDistinguir entre Problema y Solución
Distinguir entre Problema y Solución
 
Behavior Driven Development - Material de clase PMA
Behavior Driven Development - Material de clase PMABehavior Driven Development - Material de clase PMA
Behavior Driven Development - Material de clase PMA
 
Apuntes #XPweek
Apuntes #XPweekApuntes #XPweek
Apuntes #XPweek
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and Django
 
Charla Tdd Uji 032010
Charla Tdd Uji 032010Charla Tdd Uji 032010
Charla Tdd Uji 032010
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

ES6 Simplified

  • 1. Carlos Blé @carlosble Thanks to the help provided by my colleague… Alfredo Casado! ES6 Simplified
  • 2. Why ES6? (Also known as ES2015) ➔ Is the standard since June 2015! ➔ Gets rid of common and annoying gotchas ➔ Preserves all the good parts ➔ Syntactic sugar improves readability ➔ Powerful tools and libraries ➔ ES5 is still deployed into production @carlosble
  • 3. Simplicity ➔ Among all ES6 features we favor those that are powerful yet simple. We like simple code: ◆ Pass all tests ◆ Clear, expressive & consistent ◆ Duplicates no behavior ◆ Small - Minimal methods & modules Kent Beck
  • 4. It’s all about the context! Developing applications is not like developing a library or a framework Cost of understanding/maintaining code VS Cost of changing client code Adapt your practices to the context @carlosble
  • 5. Power lies in the functions @carlosble 1 export default {add, subtract}; 2 // export default {add: add, subtract: subtract}; 3 4 function add(a + b){…} 5 function subtract(a + b){…} Usage: import calculator from ‘./m.js’; calculator.add(1,1); Modules (singletons): 1 export default {calculator}; 2 // export default {calculator: calculator}; 3 function calculator(){ 4 return {add, subtract}; 5 } 6 function add(a + b){…} 7 function subtract(a + b){…} Usage: import buildCalculator from ‘./f.js’ let calculator = buildCalculator(); calculator.add(1,1); Factory functions: No need for IIFE anymore!
  • 6. Do you really need to save memory? Syntactic sugar for prototypes class Person { constructor(name) { this.name = name; } hello() { return `hi ${this.name}`; } } function Person(name) { this.name = name; } Person.prototype.hello = function() return "hi " + this.name; } 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 Warning: We avoid classes as much as we can @carlosble
  • 7. Aur revoir var! @carlosble 1 2 3 4 5 6 7 8 9 10 11 Welcome let & const function useLetInstead(){ const items = ['cat','dog']; const len = items.length; const f = []; for (let i = 0; i < len-1; i++){ f.push(() => items[i]); } console.log(f[0]()); } useLetInstead(); function doNotUseVar(){ var items = ['cat','dog']; var len = items.length; var f = []; for (var i = 0; i < len-1; i++){ f.push(function(){ return items[i]; }); } console.log(f[0]()); } doNotUseVar(); 1 2 3 4 5 6 7 8 9 10 11
  • 8. Destructuring const book = { "author": { "name": "Bob Sponge", "email": "bob@gmail.com" }, "title": "Under the sea", "other": "stuff" } let {author: {name,email}, title} = book console.log(name); // “Bob Sponge” console.log(email); // “bob@gmail.com” console.log(title); // “Under the sea” var name = book.author.name; var email = book.author.email; var title = book.title; console.log(name); // “Bob Sponge” @carlosble
  • 9. Simulating named parameters function errorMessage({ message, width = 300, height = 300, icon = ‘error.png’}){ ... } function errorMessage(options){ options = options || {}; var width = options.width || 300; var height = options.end || 300; var icon = options.icon || ‘error.png’; ... } 1 2 3 4 5 6 7 1 2 3 4 5 6 7 errorMessage({ message: ‘Ups! sorry’, icon: ‘other-icon.png’}); @carlosble
  • 10. Destructuring + default values function sum({x = 0, y = 0} = {}){ return x + y; } function destruct({a: {x}, b = 1}){ return x + b; } sum({x:5}); sum(); destruct(); destruct({a:{x:1}, b: 5}); destruct({a:{x:1}}); destruct({b:1}); 1 2 3 4 5 6 7 8 9 10 11 12 13 @carlosble
  • 11. Simulating mandatory parameters function mandatory() { throw new Error('Missing parameter'); } function foo(mustBeProvided = mandatory()) { return mustBeProvided; } function foo(mustBeProvided) { if (arguments.length < 1) throw ... if (mustBeProvided === undefined) ... } 1 2 3 4 5 6 7 1 2 3 4 @carlosble
  • 12. Rest operator function calculate(multiplier, ...numbers) { let sum = numbers.reduce( (accumulator, num) => accumulator + num ); return multiplier * sum; } function calculate() { var numbers = Array.prototype.slice.call(arguments) var multiplier = numbers.shift() var sum = numbers.reduce( function(accumulator, num){ return accumulator + num;} ) return multiplier * sum; } 1 2 3 4 5 6 1 2 3 4 5 6 7 8 @carlosble
  • 13. Promises function sendFeedback(customer, phone, answers) { const promises = []; for (let answer of answers) { promises.push(new Promise((resolve) => { answer.send(customer, phone, resolve); })); } return promises; } const promises = sendFeedback(customer, phone, answers); Promise.all(promises).then(() => showSuccessMessage()); 1 2 3 4 5 6 7 8 9 10 11 12 @carlosble
  • 15. Tools ➔ Gulp (workflow automation) ➔ Babel (compile to ES5) ➔ Browserify (require in the browser) ➔ ESLint (linter) ➔ Karma (test runner) ➔ Nodemon (manage node servers) ➔ Jasmine (unit tests) ➔ PhantomJs (unit & integration tests) ➔ Nightwatch (end2end tests) @carlosble
  • 16. Good stuff & References @carlosble ★ ES6 Katas http://es6katas.org/ ★ Tests end2end con Nightwatch [es] http://miguelviera.com/blog/testing-e2e-con- nightwatch-js-y-browserstack/ ★ Tests de integracion: Gulp+Karma+Jasmine+Nodemon [es] http://miguelviera.com/blog/integration-tests-con-gulp-karma-jasmine-phantomjs-y-nodemon/ ★ Writing a Gulpfile [en] http://www.carlosble.com/2015/09/es6-browserify-babel-gulp-jasmine/ ★ How to fix de ES6 class keyword [en] https://medium.com/javascript-scene/how-to-fix-the- es6-class-keyword-2d42bb3f4caf#.x4qojp84n ★ Let and Const [en] https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75#.pliox5rso ★ Let and Const in Depth [en] https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/
  • 17. Books! read books! @carlosble ● Implementation Patterns - Kent Beck ● JavaScript Allongé - Reginald Braithwaite ● JavaScript The Good Parts - Douglas Crockford ● 4 Rules of Simple Design - Corey Haines More books: http://www.carlosble. com/2011/02/books-you-should-read/
  • 19. Do you really need inheritance? @carlosble 1 2 3 4 5 6 7 8 9 10 Template method implemented with functional inheritance: function childClazz(){ const self = baseClazz({ compute: () => 3 }); return self; } console.log( childClazz().template()); function baseClazz(methods = {}){ let compute = () => 2; compute = methods.compute || compute; return { template : () => compute() + 1 }; } console.log( baseClazz().template()); 1 2 3 4 5 6 7 8 9