SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
2013




JavaScript revolution
New syntax ( sugar of course! )
              &
      standard library
Who I am?


       Kamil Gałuszka
Django / Objective-C / Python World
JavaScript is only a hobby (for now)




       @galuszkak


       http://solution4future.com
Introduction & Inspiration
JavaScript, JS, ECMAScript, ES

● ECMAScript 3 ( 1999 )

● ECMAScript 4 ( incompatible with third version
  2005 )

● ECMAScript 5 ( 2009 )

● ECMAScript 5.1 ( 2011 )

● TC39 - Committee for Standardization
Funny Facts


● ES 5.1 standard == 243 pages

● JavaScript: The Definitive Guide by David
  Flanagan (6th edition)== 1078 pages

● Draft of standard ES 6.0 == 421 pages

● JavaScript: The Definitive Guide by David
  Flanagan (7th edition)== ? pages ;)
Warm Up

false == "0"               false === "0"
false == "false"           null === undefined
null == undefined          "" === 0
"" == 0
NaN === NaN
6.toString();
" nt" == 0;
obj = {x:10, y:20};
delete obj.y;
obj.y == null              obj.y === null
obj.y == undefined         obj.y === undefined
ES.Next vs ES.Harmony




        ES.Next === ECMAScript 6


ES 6 is fully compatible with ES5 (strict mode)


ES.Harmony in next versions of ECMAScript
Block Scope

Two new significant keywords:
let         lock scoped variable
const       read-only variable. (couldn't be hided by other variable etc.)

Typical problem in ES 5
    var result = [];
    for (var length = 10; length--;){
       var len = length;
       result[len] = function(){ return len; }
    }
    result[5]() // 0
    result[2]() // 0

WHY?
Block Scope
Solution ES 5

   var result = [];
   for (var length = 10; length--;){
      var len = length;
      result[len] = (function(dlugosc){
           return function(){
               return dlugosc;
           }
       })(len)
   }
   result[5]() // 5
   result[2]() // 2

use closure
Block Scope



Solution ES 6 (Cleaner, nicer, AWESOME!)

   var result = [];
   for (var length = 10; length--;){
      let len = length;
      result[len] = function(){ return len;}
   }
   result[5]() // 5
   result[2]() // 2
Shorthand Object Literals



ES 5 version:              ES 6 version:

var cat = "Molly";         var cat = "Molly";
var dog = "Rex";           var dog = "Rex";
var pets = {               var pets = {cat,dog}
    'cat': cat,
    'dog': dog,
}
Shorthand Object Literals


function Animal(name){
     this.name = name;
     this.age = 0;
}

Animal.prototype = {
  roar(text){
  //old version was function roar(text)
     return `Animal ${this.name}
  roars:${text}` // template syntax
  }
}
Destructing Assignments
      (extraction from objects, swap variables)




var {parse, stringify} = JSON;

var [, areaCode, local] = /^(d{3})-(d{3}-d
{4})$/.exec("048-032-7777");

[left, right] = [right, left];
Destructuring Nested Objects
var poets = [{
        "name": "T.S. Eliot",
        "works": [{
                 "title": "The Love Song",
                 "date": 1915
            }, {
                 "title": "Rhapsody",
                 "date": 1917
            }]
   }, {
        "name": "Ezra Pound",
        "works": [{
                 "title": "Ripostes",
                 "date": 1912
            }]
   }];
Destructuring Nested Objects




ES 5 VERSION ( really hard to remember )

var author = poets[0]['name'];
var title = poets[0]['works'][1]['title'];
var date = poets[0]['works'][1]['date'];
Destructuring Nested Objects


ES 6 version (AWESOME !)
  var [{'name': author, 'works': [, {title,
  date}]}] = poets;
  // Select first author and his second book
  and store it in variables author, title, date

  `"${title}", by ${author}, was published in
  ${date}.`
  // Template creating string from this
  variables.

Rhapsody, by T.S. Eliot, was published in 1917
Default parameters


// ES 5
function Person(name, age){
   this.name = name || "Anonim";
   this.age = age || 0;
}

// ES 6
function Person(name="Anonim", age=0)
{
   this.name = name;
  this.age = 0;
}
...rest parameters

js>function f(a, b, ...r) {
   print(Array.isArray(r));
   return r.concat(a, b);
}
js>f(1, 2)
true
[1, 2]
js>f(1, 2, 3)
true
[3, 1, 2]
js>f(1, 2, 3, 4, 5)
true
[3, 4, 5, 1, 2]
...spread

//ES 5 merging array
js> var a = [1, 2]
[3, 4, 5]
js> var b = [3, 4, 5]
[1, 2]
js> a = a.concat(b)
[1, 2, 3, 4, 5]


//ES 6 merging array (AWESOME!)
js> var a = [3, 4, 5]
[3, 4, 5]
js> var b = [1, 2, ...a]
[1, 2, 3, 4, 5]
Array Comprehensions




var arr =
[ x for (x of a) if (x.color === ‘blue’) ]

var arr = [ square(x) for (x of [1,2,3,4,5]) ]




                     Example by Addy Osmani http://addyosmani.com/blog/a-few-new-thin
                     to-javascript/
Modules




module Car {
  // import …
  // export …
}




       Example by Addy Osmani http://addyosmani.com/blog/a-few-new-
       things-coming-to-javascript/
Modules

module Car {
   // Internal
   var licensePlateNo = '556-343';
   // External
   export function drive(speed, direction) {
     console.log('details:', speed, direction);
   }
   export module engine{
     export function check() { }
   }
};
                     Example by Addy Osmani http://addyosmani.com/blog/a-few-new-
                     things-coming-to-javascript/
Imports
      (Yes! YES! No requirejs or AMD needed)




import       "crypto"       as       crypto;
import { encrypt, decrypt } from "crypto";
import { encrypt: enc } from "crypto";

import {drive, engine} from Car;




                        Example by Addy Osmani http://addyosmani.com/blog/a-few-new-
                        things-coming-to-javascript/
Classes
module widgets {
  // ...
  class DropDownButton extends Widget {
    constructor(attributes) {
      super(attributes);
      this.buildUI();
    }
    buildUI() {
      this.domNode.onclick = function(){
         // ...
      };
    }
  }
                      Example by Addy Osmani http://addyosmani.com/blog/a-few-new-
}                     things-coming-to-javascript/
Classes
var widgets = (function(global) {
  function DropDownButton(attributes) {
    Widget.call(this, attributes);
    this.buildUI();
  }
  DropDownButton.prototype = Object.create
(Widget.prototype, {
    constructor: { value: DropDownButton },
    buildUI:     {
      value: function(e) {
        this.domNode.onclick = function(e) {
          // ...
        }
                     Example by Addy Osmani http://addyosmani.com/blog/a-few-new-
}}})})(this);        things-coming-to-javascript/
Compatibility Matrix




http://kangax.github.com/es5-compat-table/es6/
Thanks to...



Douglas Crockford http://javascript.crockford.com/

Kit Cambridge http://kitcambridge.be/
(His speech: http://www.youtube.com/watch?v=Dt0f2XdvriQ)

TC39

Addy Osmani http://addyosmani.com/blog/a-few-new-things-
coming-to-javascript/

Weitere ähnliche Inhalte

Was ist angesagt?

Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2
Yeqi He
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
Giordano Scalzo
 

Was ist angesagt? (20)

Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
Async Frontiers
Async FrontiersAsync Frontiers
Async Frontiers
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure way
 
Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Introduction of ES2015
Introduction of ES2015Introduction of ES2015
Introduction of ES2015
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
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...
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancement
 

Andere mochten auch

The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
Domenic Denicola
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
Domenic Denicola
 

Andere mochten auch (20)

ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Real World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScriptReal World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScript
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
JavaScript im Jahr 2016
JavaScript im Jahr 2016JavaScript im Jahr 2016
JavaScript im Jahr 2016
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
 
Client-Side Packages
Client-Side PackagesClient-Side Packages
Client-Side Packages
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
 
Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)
 
Domains!
Domains!Domains!
Domains!
 
The jsdom
The jsdomThe jsdom
The jsdom
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 

Ähnlich wie JavaScript - new features in ECMAScript 6

ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
qmmr
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
HamletDRC
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 

Ähnlich wie JavaScript - new features in ECMAScript 6 (20)

Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
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)
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Short intro to ES6 Features
Short intro to ES6 FeaturesShort intro to ES6 Features
Short intro to ES6 Features
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
"let ECMAScript = 6"
"let ECMAScript = 6" "let ECMAScript = 6"
"let ECMAScript = 6"
 
recap-js.pdf
recap-js.pdfrecap-js.pdf
recap-js.pdf
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Groovy
GroovyGroovy
Groovy
 
[React Native Tutorial] Lecture 3: More on ES6/ES2015
[React Native Tutorial] Lecture 3: More on ES6/ES2015[React Native Tutorial] Lecture 3: More on ES6/ES2015
[React Native Tutorial] Lecture 3: More on ES6/ES2015
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
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
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

JavaScript - new features in ECMAScript 6

  • 1. 2013 JavaScript revolution New syntax ( sugar of course! ) & standard library
  • 2. Who I am? Kamil Gałuszka Django / Objective-C / Python World JavaScript is only a hobby (for now) @galuszkak http://solution4future.com
  • 4. JavaScript, JS, ECMAScript, ES ● ECMAScript 3 ( 1999 ) ● ECMAScript 4 ( incompatible with third version 2005 ) ● ECMAScript 5 ( 2009 ) ● ECMAScript 5.1 ( 2011 ) ● TC39 - Committee for Standardization
  • 5. Funny Facts ● ES 5.1 standard == 243 pages ● JavaScript: The Definitive Guide by David Flanagan (6th edition)== 1078 pages ● Draft of standard ES 6.0 == 421 pages ● JavaScript: The Definitive Guide by David Flanagan (7th edition)== ? pages ;)
  • 6. Warm Up false == "0" false === "0" false == "false" null === undefined null == undefined "" === 0 "" == 0 NaN === NaN 6.toString(); " nt" == 0; obj = {x:10, y:20}; delete obj.y; obj.y == null obj.y === null obj.y == undefined obj.y === undefined
  • 7. ES.Next vs ES.Harmony ES.Next === ECMAScript 6 ES 6 is fully compatible with ES5 (strict mode) ES.Harmony in next versions of ECMAScript
  • 8. Block Scope Two new significant keywords: let lock scoped variable const read-only variable. (couldn't be hided by other variable etc.) Typical problem in ES 5 var result = []; for (var length = 10; length--;){ var len = length; result[len] = function(){ return len; } } result[5]() // 0 result[2]() // 0 WHY?
  • 9. Block Scope Solution ES 5 var result = []; for (var length = 10; length--;){ var len = length; result[len] = (function(dlugosc){ return function(){ return dlugosc; } })(len) } result[5]() // 5 result[2]() // 2 use closure
  • 10. Block Scope Solution ES 6 (Cleaner, nicer, AWESOME!) var result = []; for (var length = 10; length--;){ let len = length; result[len] = function(){ return len;} } result[5]() // 5 result[2]() // 2
  • 11. Shorthand Object Literals ES 5 version: ES 6 version: var cat = "Molly"; var cat = "Molly"; var dog = "Rex"; var dog = "Rex"; var pets = { var pets = {cat,dog} 'cat': cat, 'dog': dog, }
  • 12. Shorthand Object Literals function Animal(name){ this.name = name; this.age = 0; } Animal.prototype = { roar(text){ //old version was function roar(text) return `Animal ${this.name} roars:${text}` // template syntax } }
  • 13. Destructing Assignments (extraction from objects, swap variables) var {parse, stringify} = JSON; var [, areaCode, local] = /^(d{3})-(d{3}-d {4})$/.exec("048-032-7777"); [left, right] = [right, left];
  • 14. Destructuring Nested Objects var poets = [{ "name": "T.S. Eliot", "works": [{ "title": "The Love Song", "date": 1915 }, { "title": "Rhapsody", "date": 1917 }] }, { "name": "Ezra Pound", "works": [{ "title": "Ripostes", "date": 1912 }] }];
  • 15. Destructuring Nested Objects ES 5 VERSION ( really hard to remember ) var author = poets[0]['name']; var title = poets[0]['works'][1]['title']; var date = poets[0]['works'][1]['date'];
  • 16. Destructuring Nested Objects ES 6 version (AWESOME !) var [{'name': author, 'works': [, {title, date}]}] = poets; // Select first author and his second book and store it in variables author, title, date `"${title}", by ${author}, was published in ${date}.` // Template creating string from this variables. Rhapsody, by T.S. Eliot, was published in 1917
  • 17. Default parameters // ES 5 function Person(name, age){ this.name = name || "Anonim"; this.age = age || 0; } // ES 6 function Person(name="Anonim", age=0) { this.name = name; this.age = 0; }
  • 18. ...rest parameters js>function f(a, b, ...r) { print(Array.isArray(r)); return r.concat(a, b); } js>f(1, 2) true [1, 2] js>f(1, 2, 3) true [3, 1, 2] js>f(1, 2, 3, 4, 5) true [3, 4, 5, 1, 2]
  • 19. ...spread //ES 5 merging array js> var a = [1, 2] [3, 4, 5] js> var b = [3, 4, 5] [1, 2] js> a = a.concat(b) [1, 2, 3, 4, 5] //ES 6 merging array (AWESOME!) js> var a = [3, 4, 5] [3, 4, 5] js> var b = [1, 2, ...a] [1, 2, 3, 4, 5]
  • 20. Array Comprehensions var arr = [ x for (x of a) if (x.color === ‘blue’) ] var arr = [ square(x) for (x of [1,2,3,4,5]) ] Example by Addy Osmani http://addyosmani.com/blog/a-few-new-thin to-javascript/
  • 21. Modules module Car { // import … // export … } Example by Addy Osmani http://addyosmani.com/blog/a-few-new- things-coming-to-javascript/
  • 22. Modules module Car { // Internal var licensePlateNo = '556-343'; // External export function drive(speed, direction) { console.log('details:', speed, direction); } export module engine{ export function check() { } } }; Example by Addy Osmani http://addyosmani.com/blog/a-few-new- things-coming-to-javascript/
  • 23. Imports (Yes! YES! No requirejs or AMD needed) import "crypto" as crypto; import { encrypt, decrypt } from "crypto"; import { encrypt: enc } from "crypto"; import {drive, engine} from Car; Example by Addy Osmani http://addyosmani.com/blog/a-few-new- things-coming-to-javascript/
  • 24. Classes module widgets { // ... class DropDownButton extends Widget { constructor(attributes) { super(attributes); this.buildUI(); } buildUI() { this.domNode.onclick = function(){ // ... }; } } Example by Addy Osmani http://addyosmani.com/blog/a-few-new- } things-coming-to-javascript/
  • 25. Classes var widgets = (function(global) { function DropDownButton(attributes) { Widget.call(this, attributes); this.buildUI(); } DropDownButton.prototype = Object.create (Widget.prototype, { constructor: { value: DropDownButton }, buildUI: { value: function(e) { this.domNode.onclick = function(e) { // ... } Example by Addy Osmani http://addyosmani.com/blog/a-few-new- }}})})(this); things-coming-to-javascript/
  • 27. Thanks to... Douglas Crockford http://javascript.crockford.com/ Kit Cambridge http://kitcambridge.be/ (His speech: http://www.youtube.com/watch?v=Dt0f2XdvriQ) TC39 Addy Osmani http://addyosmani.com/blog/a-few-new-things- coming-to-javascript/