SlideShare a Scribd company logo
Rami Sayar - @ramisayar
Technical Evangelist
Microsoft Canada
• What’s ECMAScript6?
• Learning about Block Scoping
• Learning about Destructuring
• Learning about Modules and Classes
• Learning about Iterators and Generators
• Working knowledge of JavaScript and HTML5.
Note: Slides will be made available.
Fitc   whats new in es6 for web devs
Fitc   whats new in es6 for web devs
Fitc   whats new in es6 for web devs
• ECMAScript is the scripting language standardized by Ecma
International as ECMA-262.
• ECMAScript implementations include JavaScript, JScript and
ActionScript.
• Most commonly used as the basis for client-side scripting on
the Web => JavaScript.
Edition Date Published Notes
1 June 1997 First edition.
2 June 1998 Editorial changes. Aligning with ISO standard.
3 December 1999 Added regex, string handling, new control statements, try/catch, etc.
4 ABANDONED
5 December 2009 Strict mode subset, clarification, harmonization between real-world and
the spec. Added support for JSON and more object reflection.
5.1 June 2011 Aligning with ISO standard.
6 Scheduled for Mid-2015 NEW SYNTAX
7 WIP Very early stage of development.
• ES6 Standard targeted for ratification in June 2015.
• Significant update to the language.
• Major JavaScript engines are implementing
features as we speak.
• Status Tables:
• Kangax
• ES6 Matrix by Thomas Lahn:
Fitc   whats new in es6 for web devs
• ES6 in the Browser
• IE11+ has most complete ES6 support – Try it in Windows 10 TP
• Enable “Experimental JavaScript features” flag
• Chrome Canary
• Go to chrome://flags & turn on “Enable Experimental JavaScript”
• Firefox Nightly or Firefox Developer Edition
• ES6 in Node.js
• Need to use --v8-options flag
node --v8-options | grep harmony
--harmony_typeof #(enable harmony semantics for typeof)
--harmony_scoping #(enable harmony block scoping)
--harmony_modules #(enable harmony modules (implies block scoping))
--harmony_proxies #(enable harmony proxies)
--harmony_collections #(enable harmony collections (sets, maps, and weak maps))
--harmony #(enable all harmony features (except typeof))
Fitc   whats new in es6 for web devs
Fitc   whats new in es6 for web devs
• Scoping in JS is at the function-level for variables and functions.
var foo = 'FITC';
console.log(foo); // Prints 'FITC'
if (true) {
var foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
console.log(foo); // Prints 'BAR'
Fitc   whats new in es6 for web devs
• Scoping in JS is at the function-level for variables and functions.
var foo = 'FITC';
console.log(foo); // Prints 'FITC'
if (true) {
var foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
console.log(foo); // Prints 'BAR'
var foo;
foo = 'FITC';
console.log(foo); // Prints 'FITC'
if(true) {
foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
console.log(foo); // Prints 'BAR'
• ‘Hoisting’ in JavaScript
var foo = 'FITC';
if(!bar) {
console.log(foo + ' ' + bar);
// Prints 'FITC undefined'
}
var bar = '2015';
console.log(foo + ' ' + bar);
// Prints 'FITC 2015'
var foo, bar;
foo = 'FITC';
if(!bar) {
console.log(foo + ' ' + bar);
// Prints 'FITC undefined'
}
bar = '2015';
console.log(foo + ' ' + bar);
// Prints 'FITC 2015'
• Variables are ‘hoisted’ to the top even if they will never be executed
in any statement.
• You can enforce ‘hoisting’ syntactically with JSLint ‘onevar’.
• Scoping in JS is at the function-level for variables and functions.
var foo = 'FITC';
console.log(foo); // Prints 'FITC'
if (true) {
var foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
console.log(foo); // Prints 'BAR'
var foo;
foo = 'FITC';
console.log(foo); // Prints 'FITC'
function foobar() {
var foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
foobar();
console.log(foo); // Prints 'FITC'
• ES6 introduces ‘let’ & ‘const’.
• Variables declared with ‘let’ are bound to the lexical (in the
code) environment as opposed to the variable environment.
• All “block” statements (e.g. if, for, etc.) now have a lexical
environment context.
• Variables declared with ‘let’ are scoped to the block statement.
• This is inline with other C-like languages like Java, C++, etc.
• Variable ‘foo’ declared with ‘let’.
let foo = 'FITC';
console.log(foo); // Prints 'FITC'
if (true) {
let foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
console.log(foo); // Prints 'FITC'
• No ‘hoisting’ of variables when declared with ‘let’.
• Variable ‘foo’ declared with ‘const’ is also scoped to the block.
const foo = 'FITC';
console.log(foo); // Prints 'FITC'
if (true) {
let foo = 'BAR';
console.log(foo); // Prints 'BAR'
}
// foo = 'BAR';
// The above line causes “SyntaxError: Assignment to constant variable.”
console.log(foo); // Prints 'FITC'
Fitc   whats new in es6 for web devs
• Destructuring is a syntax feature that allows you to pattern
match values to variables or properties.
var [foo, bar, ABC] = ['bar', 'foo', 3];
console.log(foo + ' ' + bar + ' ' + ABC);
// Prints 'bar foo 3'
var foo = 'bar', bar = 'foo', ABC = 3;
console.log(foo + ' ' + bar + ' ' + ABC);
// Prints 'bar foo 3'
• Destructuring is a syntax feature that allows you to pattern
match values to variables or properties.
• Can be used to swap variables like in Python.
var [foo, bar] = ['bar', 'foo'];
[foo, bar] = [bar, foo];
console.log(foo + ' ' + bar);
// Prints 'foo bar'
• Destructuring is a syntax feature that allows you to pattern
match values to variables or properties.
• Not limited to arrays, you can apply destructuring to objects.
var { op: a, lhs: { op: b }, rhs: c } =
getASTNode();
• Destructuring is a syntax feature that allows you to pattern
match values to variables or properties.
• Can be used to name parameter positions, AWESOME!
function g({name: x}) {
console.log(x);
}
g({name: 5})
• Destructuring is a syntax feature that allows you to pattern
match values to variables or properties.
// Fail-soft destructuring
var [a] = [];
a === undefined;
// Fail-soft destructuring with defaults
var [a = 1] = [];
a === 1;
Fitc   whats new in es6 for web devs
Fitc   whats new in es6 for web devs
class SkinnedMesh extends THREE.Mesh {
constructor(geometry, materials) {
super(geometry, materials);
this.idMatrix = SkinnedMesh.defaultMatrix();
this.bones = [];
this.boneMatrices = [];
//...
}
update(camera) {
//...
super.update();
}
get boneCount() {
return this.bones.length;
}
set matrixType(matrixType) {
this.idMatrix = SkinnedMesh[matrixType]();
}
static defaultMatrix() {
return new THREE.Matrix4();
}
}
• Modularization in software architecture is extremely important.
• Plenty of attempts to implement modules in JavaScript.
CommonJS and Asynchronous Module Definition (AMD)
patterns had 100s of different implementations.
• Node.js had a built-in module system.
• ES6 Modules borrow the best concepts from CommonJS and
AMD.
• The implementation is defined by the JavaScript host.
• Implicitly asynchronous loading.
• Two keywords: “import” & “export”
// math.js
export var pi = 3.141593;
export function add(num1, num2) {
return num1 + num2;
}
export function circle_area(r) {
return pi * r * r;
}
// app.js
import * as math from "math";
alert("2π = " + math.add(math.pi, math.pi));
// otherApp.js
import {circle_area, pi} from "math";
alert("Area of Circle with Radius of 5 = " +
circle_area(5));
• Programmatically load modules like in AMD with system.import
• Why?
• Customize how modules are mapped to files.
• Automatically lint modules on import.
• Automatically compile CoffeeScript/TypeScript on import.
• Use other module systems…
Fitc   whats new in es6 for web devs
Fitc   whats new in es6 for web devs
“An Iterator is an object that knows how to access items from a
collection one at a time, while keeping track of its current
position within that sequence. In JavaScript an iterator is an
object that provides a next() method which returns the next item
in the sequence.”- MDN
var obj, iterator, pair;
obj = { foo: 'bar', conference: 'FITC' };
iterator = Iterator(obj);
pair = it.next(); // ["foo", "bar"]
pair = it.next(); // ["conference", "FITC"]
pair = it.next(); // StopIteration exception thrown
• for… in loop calls .next() for you automatically when used with
an iterator.
• You can also use iterators with arrays.
var evangelists = ['@ramisayar', '@tommylee',
'@scruffyfurn'];
var iterator = Iterator(evangelists);
for (let [index, item] in iterator)
console.log(index + ': ' + item);
// prints "0: @ramisayar" etc.
• Generators are factories for iterators. They are functions that
continue execution on next() and save their context for re-
entrances.
• Generators are familiar to Python programmers.
• Generators introduce function * and yield.
• Generators can replace callbacks.
function *foo() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
Fitc   whats new in es6 for web devs
var koa = require('koa');
var app = koa();
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
Fitc   whats new in es6 for web devs
IE11 Project
Spartan
(IE11+)
FF39 Chrome 43 Node io.js
const 8/8 8/8 8/8 5/8 1/8 5/8
let 8/10 8/10 0/10 w/Flag 5/10 0/10 5/10
block-level
function
declaration
Yes Yes No Yes Flag Yes
destructuring 0/30 0/30 22/30 0/30 0/30 0/30
classes 0/23 20/23 20/23 Flag 0/23 Flag
generators 0/21 0/21 18/21 14/21 Flag 12/21
Source: http://kangax.github.io/compat-table/es6
• Google Traceur, ES6 Compiler:
https://github.com/google/traceur-compiler
• Babel, ES6 Compiler: https://babeljs.io/
• Special support for JSX & React
• Support for extensions and plugins
• Continuum, ES6 Virtual Machine written with ES3:
https://github.com/Benvie/continuum
• Theoretically, support goes all the way back to IE6.
Fitc   whats new in es6 for web devs
• xto6, convert JavaScript to ES6:
https://github.com/mohebifar/xto6
• es6-shim, adding support for ES6:
https://github.com/paulmillr/es6-shim
• es6-module-loader, module loader support:
https://github.com/ModuleLoader/es6-module-loader
• What’s ECMAScript6?
• Block Scoping
• Destructuring
• Modules and Classes
• Iterators and Generators
• There is plenty more in ES6!
tw: @ramisayar | gh: @sayar
gist.github.com/sayar/d8f64a80d3a410ba5cba
slideshare.net/ramisayar
• ES6 Compatibility Table
• ES6 Browser Support
• What’s new in JavaScript?
• An introduction to ES6 Part 1: Using ES6 Today
• An introduction to ES6 Part 2: Block Scoping
• An introduction to ES6 Part 3: Destructuring
• Tracking ECMAScript 6 Support
• ES6 (a.k.a. Harmony) Features Implemented in V8 and Available in
Node
• React Introduces Support for ES6 Classes
• ECMAScript 6 Features - Introduction
• ECMAScript 6 modules: the final syntax
• The Basics Of ES6 Generators
• ECMAScript 6 and Block Scope
• Understanding ES6 Generators
• MDN - Iterators and generators
• Classes in JavaScript ES6
• ECMAScript 6 modules: the future is now
• es6-shim
• es6-module-loader
• Continuum
• Xto6
• Koa.js
• Babel.js
• traceur-compiler
©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

PDF
ES6 in Production [JSConfUY2015]
PDF
Swift core
PDF
March2004-CPerlRun
PPTX
Modern JS with ES6
PDF
ROP 輕鬆談
PDF
node ffi
PPTX
Why TypeScript?
PPTX
How Functions Work
ES6 in Production [JSConfUY2015]
Swift core
March2004-CPerlRun
Modern JS with ES6
ROP 輕鬆談
node ffi
Why TypeScript?
How Functions Work

What's hot (18)

ODP
HailDB: A NoSQL API Direct to InnoDB
PPTX
Software to the slaughter
PDF
Csp scala wixmeetup2016
PDF
Handling inline assembly in Clang and LLVM
PPTX
An introduction to ROP
PDF
Interpreter, Compiler, JIT from scratch
KEY
Alfresco the clojure way
PDF
One Shellcode to Rule Them All: Cross-Platform Exploitation
PPTX
Return Oriented Programming (ROP) Based Exploits - Part I
TXT
Sdl Basic
KEY
Aprendendo solid com exemplos
PDF
SFO15-500: VIXL
PDF
How to make the Fastest C# Serializer, In the case of ZeroFormatter
PDF
IJTC%202009%20JRuby
PDF
Introduction to clojure
PDF
Javascript basics
PDF
Low Level Exploits
PDF
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
HailDB: A NoSQL API Direct to InnoDB
Software to the slaughter
Csp scala wixmeetup2016
Handling inline assembly in Clang and LLVM
An introduction to ROP
Interpreter, Compiler, JIT from scratch
Alfresco the clojure way
One Shellcode to Rule Them All: Cross-Platform Exploitation
Return Oriented Programming (ROP) Based Exploits - Part I
Sdl Basic
Aprendendo solid com exemplos
SFO15-500: VIXL
How to make the Fastest C# Serializer, In the case of ZeroFormatter
IJTC%202009%20JRuby
Introduction to clojure
Javascript basics
Low Level Exploits
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
Ad

Viewers also liked (20)

PPTX
21st Century Crystal Ball
PPTX
Web unleashed 2015-tammyeverts
PDF
Why Everyone Should Own a Giant Robot Arm
PDF
Designing True Cross-Platform Apps
PDF
Customizing Your Process
PDF
Adapt or Die
PDF
Kickstarting Your Stupid Magazine
PDF
Reinvent Your Creative Process with Collaborative Hackathons
PDF
Squishy pixels
PDF
Creating a Smile Worthy World
PDF
Here Be Dragons – Advanced JavaScript Debugging
PDF
From Box to Bots in Minutes
PDF
The Life of <p>
PDF
Accumulations with Nicholas Felton
PDF
“It’s all a matter of Perspective.” Incorporating Play to Help Solve Problems
PDF
Building Tools for the Next Web
PDF
Open Sourcing the Secret Sauce
PDF
Learning from Science Fiction with Greg Borenstein
PDF
Making Mixed Reality Living Spaces
PDF
The Little Shop of TDD Horrors
21st Century Crystal Ball
Web unleashed 2015-tammyeverts
Why Everyone Should Own a Giant Robot Arm
Designing True Cross-Platform Apps
Customizing Your Process
Adapt or Die
Kickstarting Your Stupid Magazine
Reinvent Your Creative Process with Collaborative Hackathons
Squishy pixels
Creating a Smile Worthy World
Here Be Dragons – Advanced JavaScript Debugging
From Box to Bots in Minutes
The Life of <p>
Accumulations with Nicholas Felton
“It’s all a matter of Perspective.” Incorporating Play to Help Solve Problems
Building Tools for the Next Web
Open Sourcing the Secret Sauce
Learning from Science Fiction with Greg Borenstein
Making Mixed Reality Living Spaces
The Little Shop of TDD Horrors
Ad

Similar to Fitc whats new in es6 for web devs (20)

PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
PPTX
ES6 - JavaCro 2016
PDF
JavaScript in 2016
PPTX
JavaScript in 2016 (Codemotion Rome)
PPTX
Getting started with ES6
PDF
ESCMAScript 6: Get Ready For The Future. Now
PPTX
ES6: Features + Rails
PPTX
Getting started with ES6 : Future of javascript
PDF
JavaScript ES6
PDF
Es.next
PPTX
ECMAScript 2015
PDF
Explaining ES6: JavaScript History and What is to Come
PDF
Internal workshop es6_2015
PDF
Workshop 10: ECMAScript 6
PDF
ES6 - Next Generation Javascript
PDF
ECMAScript 6
PPTX
Intro to ES6 and why should you bother !
PDF
JavaScript - new features in ECMAScript 6
PDF
ES6: The future is now
PDF
Es6 to es5
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
ES6 - JavaCro 2016
JavaScript in 2016
JavaScript in 2016 (Codemotion Rome)
Getting started with ES6
ESCMAScript 6: Get Ready For The Future. Now
ES6: Features + Rails
Getting started with ES6 : Future of javascript
JavaScript ES6
Es.next
ECMAScript 2015
Explaining ES6: JavaScript History and What is to Come
Internal workshop es6_2015
Workshop 10: ECMAScript 6
ES6 - Next Generation Javascript
ECMAScript 6
Intro to ES6 and why should you bother !
JavaScript - new features in ECMAScript 6
ES6: The future is now
Es6 to es5

More from FITC (20)

PPTX
Cut it up
PDF
Designing for Digital Health
PDF
Profiling JavaScript Performance
PPTX
Surviving Your Tech Stack
PDF
How to Pitch Your First AR Project
PDF
Start by Understanding the Problem, Not by Delivering the Answer
PDF
Cocaine to Carrots: The Art of Telling Someone Else’s Story
PDF
Everyday Innovation
PDF
HyperLight Websites
PDF
Everything is Terrifying
PDF
Post-Earth Visions: Designing for Space and the Future Human
PDF
The Rise of the Creative Social Influencer (and How to Become One)
PDF
East of the Rockies: Developing an AR Game
PDF
Creating a Proactive Healthcare System
PDF
World Transformation: The Secret Agenda of Product Design
PDF
The Power of Now
PDF
High Performance PWAs
PDF
Rise of the JAMstack
PDF
From Closed to Open: A Journey of Self Discovery
PDF
Projects Ain’t Nobody Got Time For
Cut it up
Designing for Digital Health
Profiling JavaScript Performance
Surviving Your Tech Stack
How to Pitch Your First AR Project
Start by Understanding the Problem, Not by Delivering the Answer
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Everyday Innovation
HyperLight Websites
Everything is Terrifying
Post-Earth Visions: Designing for Space and the Future Human
The Rise of the Creative Social Influencer (and How to Become One)
East of the Rockies: Developing an AR Game
Creating a Proactive Healthcare System
World Transformation: The Secret Agenda of Product Design
The Power of Now
High Performance PWAs
Rise of the JAMstack
From Closed to Open: A Journey of Self Discovery
Projects Ain’t Nobody Got Time For

Fitc whats new in es6 for web devs

  • 1. Rami Sayar - @ramisayar Technical Evangelist Microsoft Canada
  • 2. • What’s ECMAScript6? • Learning about Block Scoping • Learning about Destructuring • Learning about Modules and Classes • Learning about Iterators and Generators
  • 3. • Working knowledge of JavaScript and HTML5. Note: Slides will be made available.
  • 7. • ECMAScript is the scripting language standardized by Ecma International as ECMA-262. • ECMAScript implementations include JavaScript, JScript and ActionScript. • Most commonly used as the basis for client-side scripting on the Web => JavaScript.
  • 8. Edition Date Published Notes 1 June 1997 First edition. 2 June 1998 Editorial changes. Aligning with ISO standard. 3 December 1999 Added regex, string handling, new control statements, try/catch, etc. 4 ABANDONED 5 December 2009 Strict mode subset, clarification, harmonization between real-world and the spec. Added support for JSON and more object reflection. 5.1 June 2011 Aligning with ISO standard. 6 Scheduled for Mid-2015 NEW SYNTAX 7 WIP Very early stage of development.
  • 9. • ES6 Standard targeted for ratification in June 2015. • Significant update to the language. • Major JavaScript engines are implementing features as we speak. • Status Tables: • Kangax • ES6 Matrix by Thomas Lahn:
  • 11. • ES6 in the Browser • IE11+ has most complete ES6 support – Try it in Windows 10 TP • Enable “Experimental JavaScript features” flag • Chrome Canary • Go to chrome://flags & turn on “Enable Experimental JavaScript” • Firefox Nightly or Firefox Developer Edition
  • 12. • ES6 in Node.js • Need to use --v8-options flag node --v8-options | grep harmony --harmony_typeof #(enable harmony semantics for typeof) --harmony_scoping #(enable harmony block scoping) --harmony_modules #(enable harmony modules (implies block scoping)) --harmony_proxies #(enable harmony proxies) --harmony_collections #(enable harmony collections (sets, maps, and weak maps)) --harmony #(enable all harmony features (except typeof))
  • 15. • Scoping in JS is at the function-level for variables and functions. var foo = 'FITC'; console.log(foo); // Prints 'FITC' if (true) { var foo = 'BAR'; console.log(foo); // Prints 'BAR' } console.log(foo); // Prints 'BAR'
  • 17. • Scoping in JS is at the function-level for variables and functions. var foo = 'FITC'; console.log(foo); // Prints 'FITC' if (true) { var foo = 'BAR'; console.log(foo); // Prints 'BAR' } console.log(foo); // Prints 'BAR' var foo; foo = 'FITC'; console.log(foo); // Prints 'FITC' if(true) { foo = 'BAR'; console.log(foo); // Prints 'BAR' } console.log(foo); // Prints 'BAR'
  • 18. • ‘Hoisting’ in JavaScript var foo = 'FITC'; if(!bar) { console.log(foo + ' ' + bar); // Prints 'FITC undefined' } var bar = '2015'; console.log(foo + ' ' + bar); // Prints 'FITC 2015' var foo, bar; foo = 'FITC'; if(!bar) { console.log(foo + ' ' + bar); // Prints 'FITC undefined' } bar = '2015'; console.log(foo + ' ' + bar); // Prints 'FITC 2015' • Variables are ‘hoisted’ to the top even if they will never be executed in any statement. • You can enforce ‘hoisting’ syntactically with JSLint ‘onevar’.
  • 19. • Scoping in JS is at the function-level for variables and functions. var foo = 'FITC'; console.log(foo); // Prints 'FITC' if (true) { var foo = 'BAR'; console.log(foo); // Prints 'BAR' } console.log(foo); // Prints 'BAR' var foo; foo = 'FITC'; console.log(foo); // Prints 'FITC' function foobar() { var foo = 'BAR'; console.log(foo); // Prints 'BAR' } foobar(); console.log(foo); // Prints 'FITC'
  • 20. • ES6 introduces ‘let’ & ‘const’. • Variables declared with ‘let’ are bound to the lexical (in the code) environment as opposed to the variable environment. • All “block” statements (e.g. if, for, etc.) now have a lexical environment context. • Variables declared with ‘let’ are scoped to the block statement. • This is inline with other C-like languages like Java, C++, etc.
  • 21. • Variable ‘foo’ declared with ‘let’. let foo = 'FITC'; console.log(foo); // Prints 'FITC' if (true) { let foo = 'BAR'; console.log(foo); // Prints 'BAR' } console.log(foo); // Prints 'FITC' • No ‘hoisting’ of variables when declared with ‘let’.
  • 22. • Variable ‘foo’ declared with ‘const’ is also scoped to the block. const foo = 'FITC'; console.log(foo); // Prints 'FITC' if (true) { let foo = 'BAR'; console.log(foo); // Prints 'BAR' } // foo = 'BAR'; // The above line causes “SyntaxError: Assignment to constant variable.” console.log(foo); // Prints 'FITC'
  • 24. • Destructuring is a syntax feature that allows you to pattern match values to variables or properties. var [foo, bar, ABC] = ['bar', 'foo', 3]; console.log(foo + ' ' + bar + ' ' + ABC); // Prints 'bar foo 3' var foo = 'bar', bar = 'foo', ABC = 3; console.log(foo + ' ' + bar + ' ' + ABC); // Prints 'bar foo 3'
  • 25. • Destructuring is a syntax feature that allows you to pattern match values to variables or properties. • Can be used to swap variables like in Python. var [foo, bar] = ['bar', 'foo']; [foo, bar] = [bar, foo]; console.log(foo + ' ' + bar); // Prints 'foo bar'
  • 26. • Destructuring is a syntax feature that allows you to pattern match values to variables or properties. • Not limited to arrays, you can apply destructuring to objects. var { op: a, lhs: { op: b }, rhs: c } = getASTNode();
  • 27. • Destructuring is a syntax feature that allows you to pattern match values to variables or properties. • Can be used to name parameter positions, AWESOME! function g({name: x}) { console.log(x); } g({name: 5})
  • 28. • Destructuring is a syntax feature that allows you to pattern match values to variables or properties. // Fail-soft destructuring var [a] = []; a === undefined; // Fail-soft destructuring with defaults var [a = 1] = []; a === 1;
  • 31. class SkinnedMesh extends THREE.Mesh { constructor(geometry, materials) { super(geometry, materials); this.idMatrix = SkinnedMesh.defaultMatrix(); this.bones = []; this.boneMatrices = []; //... }
  • 32. update(camera) { //... super.update(); } get boneCount() { return this.bones.length; } set matrixType(matrixType) { this.idMatrix = SkinnedMesh[matrixType](); }
  • 33. static defaultMatrix() { return new THREE.Matrix4(); } }
  • 34. • Modularization in software architecture is extremely important. • Plenty of attempts to implement modules in JavaScript. CommonJS and Asynchronous Module Definition (AMD) patterns had 100s of different implementations. • Node.js had a built-in module system. • ES6 Modules borrow the best concepts from CommonJS and AMD.
  • 35. • The implementation is defined by the JavaScript host. • Implicitly asynchronous loading. • Two keywords: “import” & “export”
  • 36. // math.js export var pi = 3.141593; export function add(num1, num2) { return num1 + num2; } export function circle_area(r) { return pi * r * r; }
  • 37. // app.js import * as math from "math"; alert("2π = " + math.add(math.pi, math.pi)); // otherApp.js import {circle_area, pi} from "math"; alert("Area of Circle with Radius of 5 = " + circle_area(5));
  • 38. • Programmatically load modules like in AMD with system.import • Why? • Customize how modules are mapped to files. • Automatically lint modules on import. • Automatically compile CoffeeScript/TypeScript on import. • Use other module systems…
  • 41. “An Iterator is an object that knows how to access items from a collection one at a time, while keeping track of its current position within that sequence. In JavaScript an iterator is an object that provides a next() method which returns the next item in the sequence.”- MDN
  • 42. var obj, iterator, pair; obj = { foo: 'bar', conference: 'FITC' }; iterator = Iterator(obj); pair = it.next(); // ["foo", "bar"] pair = it.next(); // ["conference", "FITC"] pair = it.next(); // StopIteration exception thrown
  • 43. • for… in loop calls .next() for you automatically when used with an iterator. • You can also use iterators with arrays. var evangelists = ['@ramisayar', '@tommylee', '@scruffyfurn']; var iterator = Iterator(evangelists); for (let [index, item] in iterator) console.log(index + ': ' + item); // prints "0: @ramisayar" etc.
  • 44. • Generators are factories for iterators. They are functions that continue execution on next() and save their context for re- entrances. • Generators are familiar to Python programmers. • Generators introduce function * and yield. • Generators can replace callbacks.
  • 45. function *foo() { yield 1; yield 2; yield 3; yield 4; yield 5; }
  • 47. var koa = require('koa'); var app = koa(); app.use(function *(){ this.body = 'Hello World'; }); app.listen(3000);
  • 49. IE11 Project Spartan (IE11+) FF39 Chrome 43 Node io.js const 8/8 8/8 8/8 5/8 1/8 5/8 let 8/10 8/10 0/10 w/Flag 5/10 0/10 5/10 block-level function declaration Yes Yes No Yes Flag Yes destructuring 0/30 0/30 22/30 0/30 0/30 0/30 classes 0/23 20/23 20/23 Flag 0/23 Flag generators 0/21 0/21 18/21 14/21 Flag 12/21 Source: http://kangax.github.io/compat-table/es6
  • 50. • Google Traceur, ES6 Compiler: https://github.com/google/traceur-compiler • Babel, ES6 Compiler: https://babeljs.io/ • Special support for JSX & React • Support for extensions and plugins • Continuum, ES6 Virtual Machine written with ES3: https://github.com/Benvie/continuum • Theoretically, support goes all the way back to IE6.
  • 52. • xto6, convert JavaScript to ES6: https://github.com/mohebifar/xto6 • es6-shim, adding support for ES6: https://github.com/paulmillr/es6-shim • es6-module-loader, module loader support: https://github.com/ModuleLoader/es6-module-loader
  • 53. • What’s ECMAScript6? • Block Scoping • Destructuring • Modules and Classes • Iterators and Generators • There is plenty more in ES6!
  • 54. tw: @ramisayar | gh: @sayar gist.github.com/sayar/d8f64a80d3a410ba5cba slideshare.net/ramisayar
  • 55. • ES6 Compatibility Table • ES6 Browser Support • What’s new in JavaScript? • An introduction to ES6 Part 1: Using ES6 Today • An introduction to ES6 Part 2: Block Scoping • An introduction to ES6 Part 3: Destructuring • Tracking ECMAScript 6 Support • ES6 (a.k.a. Harmony) Features Implemented in V8 and Available in Node • React Introduces Support for ES6 Classes
  • 56. • ECMAScript 6 Features - Introduction • ECMAScript 6 modules: the final syntax • The Basics Of ES6 Generators • ECMAScript 6 and Block Scope • Understanding ES6 Generators • MDN - Iterators and generators • Classes in JavaScript ES6 • ECMAScript 6 modules: the future is now
  • 57. • es6-shim • es6-module-loader • Continuum • Xto6 • Koa.js • Babel.js • traceur-compiler
  • 58. ©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.