SlideShare a Scribd company logo
1 of 44
Download to read offline
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Brand New JavaScript –
ECMAScript 2015
Gil Fink
CEO and Senior Consultant, sparXys
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Meet the Speaker
• sparXys CEO and Senior consultant
• ASP.NET/IIS Microsoft MVP
• Co-author of Pro Single Page Application
Development (Apress)
• Co-author of 4 Microsoft Official Courses (MOCs)
• ng-conf Israel co-organizer and GDG Rashlatz
Meetup co-organizer
Agenda
• What is ECMAScript 2015?
• Function Goodies
• String Templates
• Object Bounties
• Project Structure
• New Data Structures
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
JavaScript Evolution
Timeline
1996 1999 2009 2015 ?2016
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
ES2015 - Browser Support
• Firefox and Edge already implemented most of
ES2015 spec
• V8 (Chrome, NodeJS) already implemented a
significant part
Consult the following table:
• http://kangax.github.io/es5-compat-table/es6/
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Support in Old Browser
Versions?
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Transpilers and
Preprocessors
Compile ES2015 to ES5 using Transpilers such as
• Babel – Online REPL
• Traceur – Online Playground
Use ES2015 language features in Preprocessors such as
• TypeScript – Online Playground
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Function Goodies
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Arrow Functions
Turn this
Into this
[1, 2 ,3, 4, 5].map(function(x) {
return x * x;
});
[1, 2, 3, 4, 5].map(x => x * x);
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
No more .bind(this)!
ES5:
ES2015:
Arrow functions handle the this keyword!
Translator.prototype.translate = function(wordlist) {
return wordlist.map(function(word) {
return this.dictionary[word];
}.bind(this));
};
Translator.prototype.translate = function(wordlist) {
return wordlist.map(word => this.dictionary[word]);
};
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Old School Default Values
• The use of || adds confusion to your source code!
function eat(fruit) {
var food = fruit || ‘banana’;
console.log('Koko eats: ' + fruit);
}
eat();
// Koko eats: banana
eat('apple');
// Koko eats: apple
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
ES2015 Default Values
function eat(fruit = 'banana') {
console.log('Koko eats: ' + fruit);
}
eat();
// Koko eats: banana
eat('apple');
// Koko eats: apple
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Rest
• Gets as array parameter the rest of the passed in
arguments
monkeyLog('Kiki', 'banana', 'monkey business');
function monkeyLog(monkeyName, ...stuff) {
stuff.forEach(thing => console.log(monkeyName + ' says ' + thing));
}
// Kiki says banana
// Kiki says monkey business
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Spread (inverse Rest)
• Spreads an array into function arguments
o In the order of the array elements
function f (x, y, z) {
return x + y + z;
}
f(...[1,2,3])
// 6
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Block Scope
• What would the output of the following code?
var events = ['click', 'dblclick', 'keydown', 'keyup'];
for (var i = 0; i < events.length; i++) {
var event = events[i];
element.addEventListener(event, function() {
console.log('got event: ' + event);
});
}
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
let - To The Rescue
• let allows to define a block-scoped variable:
var events = ['click', 'dblclick', 'keydown', 'keyup'];
for (var i = 0; i < events.length; i++) {
let event = events[i];
element.addEventListener(event, function() {
console.log('got event: ' + event);
});
}
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Const
• Trying to set a const during runtime will raise an
error!
function calcWeight(lion) {
const pi = 3.14159265359;
if (lion.name === ‘Simba') {
pi = 3.07; // Error! Don’t do that at home kids…
}
return lion.height * lion.age / pi * pi;
}
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
String Templates
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
String Templates
• Use backticks ( ` ) for defining template strings
• Use curly brackets to embed values inside backticks
// Multiline allowed!
var str = `In older versions of JavaScript this is
not legal.`;
// Easy embedding of values inside strings
var total = 30;
var price = `The monkey costs ${total} dollars`;
var priceWithTax = `The monkey costs ${total*1.18} dollars with tax`;
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
String Templates - Tags
function tax(str, price) {
// str === ['This monkey costs ', ' dollars']
const TAX_RATE = 1.07;
return str[0] + price*TAX_RATE + str[1];
}
var price = 25;
var messageWithTax = tax`The monkey costs ${price} dollars`
// The monkey costs 26.75 dollars
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Tags for i18n
• An interesting use-case for tags is i18n translations
var name = 'Lucas';
var greeting = locale`Hello, ${name}! How are you today?`;
// Bonjour, Lucas! Ça va comment aujourd'hui?
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Tags for HTML Escaping
• We can use tags for escaping HTML content:
var monkey = {
name: 'Charlie',
profession: 'Hacker!!!<script>alert("boo")</script>'
};
safehtml`
<h1>Monkey details: ${monkey.name}</h1>
<div>Works as ${monkey.profession}</div>
`
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Object Bounties
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Destructuring
• List matching:
• Object Assignment:
let [first, , third] = [1,2,3];
function getMonkey() {
return {name: 'Bobi', age: 25};
}
let {name, age} = getMonkey();
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Argument Destructuring
• Works with default values
• Good solution for options parameter
function summonMonkey({name}) {
console.log(`Summoning ${name}`);
}
summonMonkey({name: 'Charlie'});
// Summoning Charlie
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Enhanced Object Literals
function getZoo(zooKeeper, monkeyType) {
return {
zooKeeper,
feedAnimals() {
// ...
},
[monkeyType]: new Monkey()
};
}
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Project Structure
classes & modules
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} is speaking…`);
}
}
var a = new Animal('Yogi');
a.speak();
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Inheritance
class Monkey extends Animal {
constructor(name, age) {
super(name);
this.age = age;
}
speak() {
console.log('Give me Banana!');
}
}
var monkey = new Monkey('Kiki', 4);
monkey.speak();
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Static Methods
class Gorilla extends Monkey {
static averageWeight() {
return 150;
}
}
console.log(Gorilla.averageWeight());
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Modules
• math.js
• app.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
import {sum, pi} from './math';
console.log("2π = " + sum(pi, pi));
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
New Data Structures
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Sets
var words = new Set();
words.add('hello').add('goodbye').add('hello');
// words.size === 2;
// words.has('hello') === true;
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Maps
// Maps
var m = new Map();
m.set('hello', 42);
var monkey = new Monkey();
m.set(monkey, 34); // objects can be keys!
// m.get(monkey) === 34;
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Weak Maps
• The keys have weak reference and will not prevent
object from being garbage collected
• There is also WeakSet
• WeakMap and WeekSet are not iterable
var zoo = new WeakMap();
var monkey = { name: 'Kiki' };
zoo.set(monkey, 42);
console.log(zoo.get('monkey'));
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
for-of Loop
• The for-of loop iterates over the values
o Of an array
o Of An iteratable object (which isn’t not covered in this session)
let sum = 0;
for(let number of [1, 2, 3]) {
sum += number;
}
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Extras
There's much more in ES2015:
• Iterators
• Generators
• Symbols
• Tail recursion
• Promises
• Proxies, Reflection
• Learn more at:
https://github.com/lukehoban/es6features
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Should I Use ES2015
Today?
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Questions?
Summary
• JavaScript is a dominant language that evolved
through the years
• ECMAScript 2015 brings a lot of new options
into the JavaScript language
• Learn ECMAScript 2015 today!
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Resources
• Download the slide deck:
• My Blog – http://www.gilfink.net
• Follow me on Twitter – @gilfink
Join the conversation on Twitter:
@SoftArchConf #SoftwareArchitect2015
Thank You!

More Related Content

Similar to Brand New JavaScript - ECMAScript 2015

First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS DevelopmentSasha Goldshtein
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in CodeEamonn Boyle
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Play framework: lessons learned
Play framework: lessons learnedPlay framework: lessons learned
Play framework: lessons learnedPeter Hilton
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8Giovanni Bassi
 
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays
 
APIs for the Internet of Things
APIs for the Internet of ThingsAPIs for the Internet of Things
APIs for the Internet of ThingsKinoma
 
[ABC2018Spring]Flutterアプリ開発入門
[ABC2018Spring]Flutterアプリ開発入門[ABC2018Spring]Flutterアプリ開発入門
[ABC2018Spring]Flutterアプリ開発入門Kenichi Kambara
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliRebecca Eloise Hogg
 
Secure Programming Practices in C++ (NDC Oslo 2018)
Secure Programming Practices in C++ (NDC Oslo 2018)Secure Programming Practices in C++ (NDC Oslo 2018)
Secure Programming Practices in C++ (NDC Oslo 2018)Patricia Aas
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Pritam Samanta
 

Similar to Brand New JavaScript - ECMAScript 2015 (20)

First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in Code
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Play framework: lessons learned
Play framework: lessons learnedPlay framework: lessons learned
Play framework: lessons learned
 
Playing With The Web
Playing With The WebPlaying With The Web
Playing With The Web
 
Functions using stack and heap
Functions using stack and heapFunctions using stack and heap
Functions using stack and heap
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8
 
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
 
APIs for the Internet of Things
APIs for the Internet of ThingsAPIs for the Internet of Things
APIs for the Internet of Things
 
[ABC2018Spring]Flutterアプリ開発入門
[ABC2018Spring]Flutterアプリ開発入門[ABC2018Spring]Flutterアプリ開発入門
[ABC2018Spring]Flutterアプリ開発入門
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
 
Secure Programming Practices in C++ (NDC Oslo 2018)
Secure Programming Practices in C++ (NDC Oslo 2018)Secure Programming Practices in C++ (NDC Oslo 2018)
Secure Programming Practices in C++ (NDC Oslo 2018)
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#
 
Async and Parallel F#
Async and Parallel F#Async and Parallel F#
Async and Parallel F#
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 

More from Gil Fink

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech SpeakerGil Fink
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api Gil Fink
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedGil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedGil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speakerGil Fink
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service WorkersGil Fink
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular AnimationsGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?Gil Fink
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type scriptGil Fink
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type scriptGil Fink
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2Gil Fink
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSGil Fink
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databasesGil Fink
 

More from Gil Fink (20)

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech Speaker
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speaker
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service Workers
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type script
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Web components
Web componentsWeb components
Web components
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databases
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Brand New JavaScript - ECMAScript 2015

  • 1. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Brand New JavaScript – ECMAScript 2015 Gil Fink CEO and Senior Consultant, sparXys Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015
  • 2. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Meet the Speaker • sparXys CEO and Senior consultant • ASP.NET/IIS Microsoft MVP • Co-author of Pro Single Page Application Development (Apress) • Co-author of 4 Microsoft Official Courses (MOCs) • ng-conf Israel co-organizer and GDG Rashlatz Meetup co-organizer
  • 3. Agenda • What is ECMAScript 2015? • Function Goodies • String Templates • Object Bounties • Project Structure • New Data Structures Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015
  • 4. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015
  • 5. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 JavaScript Evolution Timeline 1996 1999 2009 2015 ?2016
  • 6. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 ES2015 - Browser Support • Firefox and Edge already implemented most of ES2015 spec • V8 (Chrome, NodeJS) already implemented a significant part Consult the following table: • http://kangax.github.io/es5-compat-table/es6/
  • 7. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Support in Old Browser Versions?
  • 8. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Transpilers and Preprocessors Compile ES2015 to ES5 using Transpilers such as • Babel – Online REPL • Traceur – Online Playground Use ES2015 language features in Preprocessors such as • TypeScript – Online Playground
  • 9. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Function Goodies
  • 10. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015
  • 11. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Arrow Functions Turn this Into this [1, 2 ,3, 4, 5].map(function(x) { return x * x; }); [1, 2, 3, 4, 5].map(x => x * x);
  • 12. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 No more .bind(this)! ES5: ES2015: Arrow functions handle the this keyword! Translator.prototype.translate = function(wordlist) { return wordlist.map(function(word) { return this.dictionary[word]; }.bind(this)); }; Translator.prototype.translate = function(wordlist) { return wordlist.map(word => this.dictionary[word]); };
  • 13. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Old School Default Values • The use of || adds confusion to your source code! function eat(fruit) { var food = fruit || ‘banana’; console.log('Koko eats: ' + fruit); } eat(); // Koko eats: banana eat('apple'); // Koko eats: apple
  • 14. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 ES2015 Default Values function eat(fruit = 'banana') { console.log('Koko eats: ' + fruit); } eat(); // Koko eats: banana eat('apple'); // Koko eats: apple
  • 15. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Rest • Gets as array parameter the rest of the passed in arguments monkeyLog('Kiki', 'banana', 'monkey business'); function monkeyLog(monkeyName, ...stuff) { stuff.forEach(thing => console.log(monkeyName + ' says ' + thing)); } // Kiki says banana // Kiki says monkey business
  • 16. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Spread (inverse Rest) • Spreads an array into function arguments o In the order of the array elements function f (x, y, z) { return x + y + z; } f(...[1,2,3]) // 6
  • 17. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Block Scope • What would the output of the following code? var events = ['click', 'dblclick', 'keydown', 'keyup']; for (var i = 0; i < events.length; i++) { var event = events[i]; element.addEventListener(event, function() { console.log('got event: ' + event); }); }
  • 18. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 let - To The Rescue • let allows to define a block-scoped variable: var events = ['click', 'dblclick', 'keydown', 'keyup']; for (var i = 0; i < events.length; i++) { let event = events[i]; element.addEventListener(event, function() { console.log('got event: ' + event); }); }
  • 19. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Const • Trying to set a const during runtime will raise an error! function calcWeight(lion) { const pi = 3.14159265359; if (lion.name === ‘Simba') { pi = 3.07; // Error! Don’t do that at home kids… } return lion.height * lion.age / pi * pi; }
  • 20. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 String Templates
  • 21. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 String Templates • Use backticks ( ` ) for defining template strings • Use curly brackets to embed values inside backticks // Multiline allowed! var str = `In older versions of JavaScript this is not legal.`; // Easy embedding of values inside strings var total = 30; var price = `The monkey costs ${total} dollars`; var priceWithTax = `The monkey costs ${total*1.18} dollars with tax`;
  • 22. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 String Templates - Tags function tax(str, price) { // str === ['This monkey costs ', ' dollars'] const TAX_RATE = 1.07; return str[0] + price*TAX_RATE + str[1]; } var price = 25; var messageWithTax = tax`The monkey costs ${price} dollars` // The monkey costs 26.75 dollars
  • 23. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Tags for i18n • An interesting use-case for tags is i18n translations var name = 'Lucas'; var greeting = locale`Hello, ${name}! How are you today?`; // Bonjour, Lucas! Ça va comment aujourd'hui?
  • 24. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Tags for HTML Escaping • We can use tags for escaping HTML content: var monkey = { name: 'Charlie', profession: 'Hacker!!!<script>alert("boo")</script>' }; safehtml` <h1>Monkey details: ${monkey.name}</h1> <div>Works as ${monkey.profession}</div> `
  • 25. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Object Bounties
  • 26. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Destructuring • List matching: • Object Assignment: let [first, , third] = [1,2,3]; function getMonkey() { return {name: 'Bobi', age: 25}; } let {name, age} = getMonkey();
  • 27. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Argument Destructuring • Works with default values • Good solution for options parameter function summonMonkey({name}) { console.log(`Summoning ${name}`); } summonMonkey({name: 'Charlie'}); // Summoning Charlie
  • 28. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Enhanced Object Literals function getZoo(zooKeeper, monkeyType) { return { zooKeeper, feedAnimals() { // ... }, [monkeyType]: new Monkey() }; }
  • 29. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Project Structure classes & modules
  • 30. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Classes class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} is speaking…`); } } var a = new Animal('Yogi'); a.speak();
  • 31. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Inheritance class Monkey extends Animal { constructor(name, age) { super(name); this.age = age; } speak() { console.log('Give me Banana!'); } } var monkey = new Monkey('Kiki', 4); monkey.speak();
  • 32. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Static Methods class Gorilla extends Monkey { static averageWeight() { return 150; } } console.log(Gorilla.averageWeight());
  • 33. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Modules • math.js • app.js export function sum(x, y) { return x + y; } export var pi = 3.141593; import {sum, pi} from './math'; console.log("2π = " + sum(pi, pi));
  • 34. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 New Data Structures
  • 35. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Sets var words = new Set(); words.add('hello').add('goodbye').add('hello'); // words.size === 2; // words.has('hello') === true;
  • 36. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Maps // Maps var m = new Map(); m.set('hello', 42); var monkey = new Monkey(); m.set(monkey, 34); // objects can be keys! // m.get(monkey) === 34;
  • 37. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Weak Maps • The keys have weak reference and will not prevent object from being garbage collected • There is also WeakSet • WeakMap and WeekSet are not iterable var zoo = new WeakMap(); var monkey = { name: 'Kiki' }; zoo.set(monkey, 42); console.log(zoo.get('monkey'));
  • 38. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 for-of Loop • The for-of loop iterates over the values o Of an array o Of An iteratable object (which isn’t not covered in this session) let sum = 0; for(let number of [1, 2, 3]) { sum += number; }
  • 39. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Extras There's much more in ES2015: • Iterators • Generators • Symbols • Tail recursion • Promises • Proxies, Reflection • Learn more at: https://github.com/lukehoban/es6features
  • 40. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Should I Use ES2015 Today?
  • 41. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Questions?
  • 42. Summary • JavaScript is a dominant language that evolved through the years • ECMAScript 2015 brings a lot of new options into the JavaScript language • Learn ECMAScript 2015 today! Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015
  • 43. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Resources • Download the slide deck: • My Blog – http://www.gilfink.net • Follow me on Twitter – @gilfink
  • 44. Join the conversation on Twitter: @SoftArchConf #SoftwareArchitect2015 Thank You!