SlideShare a Scribd company logo
1 of 24
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
SELA DEVELOPER PRACTICE
June 29-July 3, 2014
Ran Wahle
What’s new in ECMAScript 6
var links = document.querySelectorAll(“a”);
for (var i = 0; i < links.length; i++)
{
links[i].onclick = function(){alert(i);};
}
Warmup- what’s wrong with this code
var links = document.querySelectorAll(“a”);
for (var i = 0; i < links.length; i++)
{
var clickFunc = function(j) {
links[j].onclick = function(){alert(j);};
}(i);
}
Warmup- fix the wrong code (v5)
var links = document.querySelectorAll("a");
for (var i = 0; i < links.length; i++)
{
let j = i;
links[j].onclick = function(){alert(j);};
}
Fix the code (v6)
Syntactic Sugar
Promises
Modules & Classes
Platform support
Summary
Agenda
var firstName = ‘Ran’;
var lastName = ‘Wahle’;
//ES5
var person = {firstName: firstName, lastName: lastName};
//ES6
var person = {firstName, lastName};
Syntactic sugars: Shorthand objects
var {firstName, lastName} = person;
//firstName === ‘Ran’
//lastName === ‘Wahle’
Syntactic Sugar : Object destructure
var phoneParts = /^(d{3})-(d{2})-(d{7})$/.exec("972-54-
3050897");
var countryCode = phoneParts[0];
var areaCode = phoneParts[1];
var local = phoneParts[2];
console.log("countryCode", countryCode);
console.log("areaCode", areaCode);
console.log("local", local);
Desctructure: extract from array
var [,countryCode, areaCode, local] = /^(d{3})-(d{2})-
(d{7})$/.exec("972-54-3050897");
console.log("countryCode", countryCode);
console.log("areaCode", areaCode);
console.log("local", local);
Destructure of Array
var family= { father: {firstName: 'Dan', lastName: 'Wahle'} ,
mother: {firstName: 'Nira', lastName: 'Wahle'},
children: [
{firstName: 'Ran', lastName: 'Wahle'},
{firstName: 'Ayala', lastName: 'Fridman'},
{firstName: 'Tamar',lastName: 'Wahle'},
{firstName: 'Yair', lastName: 'Wahle'},
{firstName: 'Giyora', lastName: 'Wahle'},
{firstName: 'Amnon', lastName: 'Wahle'}
] }
//Query the first name of the family’s oldest child
var {'children': [{'firstName': name}]} = family;
console.log(name)
Nested objects destructure
var functionWithDefault = function(param1 = “val1”)
{
console.log(param1);
};
functionWithDefault();
//Ouputs : “val1”
Syntactic Sugar: Default parameters
var functionWithParameterCollection = function(paramA, paramB,
...theRest)
{
console.log(theRest);
};
functionWithParameterCollection ('a','b','c','d','e');
//output ["c", "d", "e"]
Syntactic sugar: parameters collection
var array = [1,2,3,4,5,6];
//es5
array.forEach(function(a) {console.log(a);});
//es6
array.forEach(a => console.log(a));
Arrow functions (lambda expression)
var promise = new Promise(
function(resolve, reject)
{
var request = new XMLHttpRequest();
request.open('GET', ‘/', true);
request.onreadystatechange = () =>
{resolve(request.response);
};
request.send();
}
).then(result =>
{console.log("Result", result, "Promise", promise);},
error =>
{console.error("Promise error", error);});
Promises (no q.js library involved)
var numbers = [1,2,3,4,5,6];
var squares = [x*x for (x of numbers)];
//query the array
var evens = [number for (number of numbers)
if (number % 2 === 0)]
console.log(numbers, squares, evens);
//output
[1, 2, 3, 4, 5, 6] [1, 4, 9, 16, 25, 36] [2, 4, 6]
Build array from another array
class Vehicle {
constructor( name, year ) {
this.name = name;
this.year = year;
}
summary() {
return "This vehicle's name is " + this.name + " and it
was manufactured in " + this.year;
}
}
var myCar = new Vehicle(‘Susita’, 1975);
Classes
Example from Daniel Struk’s blog http://dstrunk.com/ecmascript-6-features-classes/
class SemiTruck extends Vehicle {
constructor( x, y ) {
super( x, y );
this.wheels = 18;
}
}
Inherritence
Example from Daniel Struk’s blog http://dstrunk.com/ecmascript-6-features-classes/
Demo
Classes demo using Traceur
Modules
AMD implementation without libraries
No need to wrap an entire code in a function
Export
var innerResult = 0;
var addition = function(number)
{
console.log(typeof number, typeof innerResult);
innerResult = innerResult + number;
if (isNaN(innerResult))
{
innerResult = 0;
}
return innerResult;
};
//Export
export {addition};
Import
import {addition} from 'calculator';
document.querySelector('#btnAdd').onclick = function()
{
var number =
parseInt(document.querySelector('#txtNumber').value);
document.querySelector('#spnResult').innerText =
addition(number);
}
Demo
Very simple Calculator
Platform support
See http://kangax.github.io/compat-table/es6/ for updates
ECMAScript 6 has many features
Many of them are already implemented
in various libraries
Its standards are still in process
Many platforms not yet supports it
Summary
Questions
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Thank You
http://blogs.Microsoft.co.il/ranw
Twitter: @ranwahle
ranw@sela.co.il

More Related Content

What's hot (6)

Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 
Martin Anderson - threads v actors
Martin Anderson - threads v actorsMartin Anderson - threads v actors
Martin Anderson - threads v actors
 
SPARQLing cocktails
SPARQLing cocktailsSPARQLing cocktails
SPARQLing cocktails
 
Automated code audits
Automated code auditsAutomated code audits
Automated code audits
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
Documentation Inference for Exceptions
Documentation Inference for ExceptionsDocumentation Inference for Exceptions
Documentation Inference for Exceptions
 

Similar to What's new in ECMAScript 6

02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
crgwbr
 

Similar to What's new in ECMAScript 6 (20)

Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
More than syntax
More than syntaxMore than syntax
More than syntax
 
What's New in JavaScript
What's New in JavaScriptWhat's New in JavaScript
What's New in JavaScript
 
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()
 
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...
 
JavaScript for Web Analysts
JavaScript for Web AnalystsJavaScript for Web Analysts
JavaScript for Web Analysts
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
 
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
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
 
PHPunit and you
PHPunit and youPHPunit and you
PHPunit and you
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Testing for software engineers
Testing for software engineersTesting for software engineers
Testing for software engineers
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 

More from Ran Wahle

More from Ran Wahle (20)

MicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleanedMicroFrontend With Iframes, dirty laundry that can be cleaned
MicroFrontend With Iframes, dirty laundry that can be cleaned
 
Into React-DOM.pptx
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptx
 
Lets go to the background
Lets go to the backgroundLets go to the background
Lets go to the background
 
Permissions api
Permissions apiPermissions api
Permissions api
 
Lets go vanilla
Lets go vanillaLets go vanilla
Lets go vanilla
 
Custom elements
Custom elements Custom elements
Custom elements
 
Web workers
Web workers Web workers
Web workers
 
Using legacy code with micro frontends
Using legacy code with micro frontendsUsing legacy code with micro frontends
Using legacy code with micro frontends
 
Ngrx one-effect
Ngrx one-effectNgrx one-effect
Ngrx one-effect
 
Angular migration
Angular migrationAngular migration
Angular migration
 
Javascript async / await Frontend-IL
Javascript async / await Frontend-ILJavascript async / await Frontend-IL
Javascript async / await Frontend-IL
 
Boost js state management
Boost js state managementBoost js state management
Boost js state management
 
Angular 2.0 change detection
Angular 2.0 change detectionAngular 2.0 change detection
Angular 2.0 change detection
 
Code migration from Angular 1.x to Angular 2.0
Code migration from Angular 1.x to Angular 2.0Code migration from Angular 1.x to Angular 2.0
Code migration from Angular 1.x to Angular 2.0
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Asyncawait in typescript
Asyncawait in typescriptAsyncawait in typescript
Asyncawait in typescript
 
Angular%201%20to%20angular%202
Angular%201%20to%20angular%202Angular%201%20to%20angular%202
Angular%201%20to%20angular%202
 
What’s new in angular 2 - From FrontEnd IL Meetup
What’s new in angular 2 - From FrontEnd IL MeetupWhat’s new in angular 2 - From FrontEnd IL Meetup
What’s new in angular 2 - From FrontEnd IL Meetup
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 

Recently uploaded

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
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
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
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 🔝✔️✔️
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

What's new in ECMAScript 6

  • 1. © Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com SELA DEVELOPER PRACTICE June 29-July 3, 2014 Ran Wahle What’s new in ECMAScript 6
  • 2. var links = document.querySelectorAll(“a”); for (var i = 0; i < links.length; i++) { links[i].onclick = function(){alert(i);}; } Warmup- what’s wrong with this code
  • 3. var links = document.querySelectorAll(“a”); for (var i = 0; i < links.length; i++) { var clickFunc = function(j) { links[j].onclick = function(){alert(j);}; }(i); } Warmup- fix the wrong code (v5)
  • 4. var links = document.querySelectorAll("a"); for (var i = 0; i < links.length; i++) { let j = i; links[j].onclick = function(){alert(j);}; } Fix the code (v6)
  • 5. Syntactic Sugar Promises Modules & Classes Platform support Summary Agenda
  • 6. var firstName = ‘Ran’; var lastName = ‘Wahle’; //ES5 var person = {firstName: firstName, lastName: lastName}; //ES6 var person = {firstName, lastName}; Syntactic sugars: Shorthand objects
  • 7. var {firstName, lastName} = person; //firstName === ‘Ran’ //lastName === ‘Wahle’ Syntactic Sugar : Object destructure
  • 8. var phoneParts = /^(d{3})-(d{2})-(d{7})$/.exec("972-54- 3050897"); var countryCode = phoneParts[0]; var areaCode = phoneParts[1]; var local = phoneParts[2]; console.log("countryCode", countryCode); console.log("areaCode", areaCode); console.log("local", local); Desctructure: extract from array
  • 9. var [,countryCode, areaCode, local] = /^(d{3})-(d{2})- (d{7})$/.exec("972-54-3050897"); console.log("countryCode", countryCode); console.log("areaCode", areaCode); console.log("local", local); Destructure of Array
  • 10. var family= { father: {firstName: 'Dan', lastName: 'Wahle'} , mother: {firstName: 'Nira', lastName: 'Wahle'}, children: [ {firstName: 'Ran', lastName: 'Wahle'}, {firstName: 'Ayala', lastName: 'Fridman'}, {firstName: 'Tamar',lastName: 'Wahle'}, {firstName: 'Yair', lastName: 'Wahle'}, {firstName: 'Giyora', lastName: 'Wahle'}, {firstName: 'Amnon', lastName: 'Wahle'} ] } //Query the first name of the family’s oldest child var {'children': [{'firstName': name}]} = family; console.log(name) Nested objects destructure
  • 11. var functionWithDefault = function(param1 = “val1”) { console.log(param1); }; functionWithDefault(); //Ouputs : “val1” Syntactic Sugar: Default parameters
  • 12. var functionWithParameterCollection = function(paramA, paramB, ...theRest) { console.log(theRest); }; functionWithParameterCollection ('a','b','c','d','e'); //output ["c", "d", "e"] Syntactic sugar: parameters collection
  • 13. var array = [1,2,3,4,5,6]; //es5 array.forEach(function(a) {console.log(a);}); //es6 array.forEach(a => console.log(a)); Arrow functions (lambda expression)
  • 14. var promise = new Promise( function(resolve, reject) { var request = new XMLHttpRequest(); request.open('GET', ‘/', true); request.onreadystatechange = () => {resolve(request.response); }; request.send(); } ).then(result => {console.log("Result", result, "Promise", promise);}, error => {console.error("Promise error", error);}); Promises (no q.js library involved)
  • 15. var numbers = [1,2,3,4,5,6]; var squares = [x*x for (x of numbers)]; //query the array var evens = [number for (number of numbers) if (number % 2 === 0)] console.log(numbers, squares, evens); //output [1, 2, 3, 4, 5, 6] [1, 4, 9, 16, 25, 36] [2, 4, 6] Build array from another array
  • 16. class Vehicle { constructor( name, year ) { this.name = name; this.year = year; } summary() { return "This vehicle's name is " + this.name + " and it was manufactured in " + this.year; } } var myCar = new Vehicle(‘Susita’, 1975); Classes Example from Daniel Struk’s blog http://dstrunk.com/ecmascript-6-features-classes/
  • 17. class SemiTruck extends Vehicle { constructor( x, y ) { super( x, y ); this.wheels = 18; } } Inherritence Example from Daniel Struk’s blog http://dstrunk.com/ecmascript-6-features-classes/
  • 19. Modules AMD implementation without libraries No need to wrap an entire code in a function Export var innerResult = 0; var addition = function(number) { console.log(typeof number, typeof innerResult); innerResult = innerResult + number; if (isNaN(innerResult)) { innerResult = 0; } return innerResult; }; //Export export {addition}; Import import {addition} from 'calculator'; document.querySelector('#btnAdd').onclick = function() { var number = parseInt(document.querySelector('#txtNumber').value); document.querySelector('#spnResult').innerText = addition(number); }
  • 22. ECMAScript 6 has many features Many of them are already implemented in various libraries Its standards are still in process Many platforms not yet supports it Summary
  • 24. © Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com Thank You http://blogs.Microsoft.co.il/ranw Twitter: @ranwahle ranw@sela.co.il