SlideShare a Scribd company logo
1 of 58
Download to read offline
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.
• 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:
• 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))
• 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'
• 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'
• 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;
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…
“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;
}
var koa = require('koa');
var app = koa();
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
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.
• 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

What's hot

HailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDBHailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDBstewartsmith
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMMin-Yih Hsu
 
An introduction to ROP
An introduction to ROPAn introduction to ROP
An introduction to ROPSaumil Shah
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure wayCarlo Sciolla
 
One Shellcode to Rule Them All: Cross-Platform Exploitation
One Shellcode to Rule Them All: Cross-Platform ExploitationOne Shellcode to Rule Them All: Cross-Platform Exploitation
One Shellcode to Rule Them All: Cross-Platform ExploitationQuinn Wilton
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplosvinibaggio
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXLLinaro
 
How to make the Fastest C# Serializer, In the case of ZeroFormatter
How to make the Fastest C# Serializer, In the case of ZeroFormatterHow to make the Fastest C# Serializer, In the case of ZeroFormatter
How to make the Fastest C# Serializer, In the case of ZeroFormatterYoshifumi Kawai
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例National Cheng Kung University
 

What's hot (18)

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

Viewers also liked

21st Century Crystal Ball
21st Century Crystal Ball21st Century Crystal Ball
21st Century Crystal BallFITC
 
Web unleashed 2015-tammyeverts
Web unleashed 2015-tammyevertsWeb unleashed 2015-tammyeverts
Web unleashed 2015-tammyevertsFITC
 
Why Everyone Should Own a Giant Robot Arm
Why Everyone Should Own a Giant Robot ArmWhy Everyone Should Own a Giant Robot Arm
Why Everyone Should Own a Giant Robot ArmFITC
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform AppsFITC
 
Customizing Your Process
Customizing Your ProcessCustomizing Your Process
Customizing Your ProcessFITC
 
Adapt or Die
Adapt or DieAdapt or Die
Adapt or DieFITC
 
Kickstarting Your Stupid Magazine
Kickstarting Your Stupid MagazineKickstarting Your Stupid Magazine
Kickstarting Your Stupid MagazineFITC
 
Reinvent Your Creative Process with Collaborative Hackathons
Reinvent Your Creative Process with Collaborative HackathonsReinvent Your Creative Process with Collaborative Hackathons
Reinvent Your Creative Process with Collaborative HackathonsFITC
 
Squishy pixels
Squishy pixelsSquishy pixels
Squishy pixelsFITC
 
Creating a Smile Worthy World
Creating a Smile Worthy WorldCreating a Smile Worthy World
Creating a Smile Worthy WorldFITC
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingFITC
 
From Box to Bots in Minutes
From Box to Bots in MinutesFrom Box to Bots in Minutes
From Box to Bots in MinutesFITC
 
The Life of <p>
The Life of <p>The Life of <p>
The Life of <p>FITC
 
Accumulations with Nicholas Felton
Accumulations with Nicholas FeltonAccumulations with Nicholas Felton
Accumulations with Nicholas FeltonFITC
 
“It’s all a matter of Perspective.” Incorporating Play to Help Solve Problems
“It’s all a matter of Perspective.” Incorporating Play to Help Solve Problems“It’s all a matter of Perspective.” Incorporating Play to Help Solve Problems
“It’s all a matter of Perspective.” Incorporating Play to Help Solve ProblemsFITC
 
Building Tools for the Next Web
Building Tools for the Next WebBuilding Tools for the Next Web
Building Tools for the Next WebFITC
 
Open Sourcing the Secret Sauce
Open Sourcing the Secret SauceOpen Sourcing the Secret Sauce
Open Sourcing the Secret SauceFITC
 
Learning from Science Fiction with Greg Borenstein
Learning from Science Fiction with Greg BorensteinLearning from Science Fiction with Greg Borenstein
Learning from Science Fiction with Greg BorensteinFITC
 
Making Mixed Reality Living Spaces
Making Mixed Reality Living SpacesMaking Mixed Reality Living Spaces
Making Mixed Reality Living SpacesFITC
 
The Little Shop of TDD Horrors
The Little Shop of TDD HorrorsThe Little Shop of TDD Horrors
The Little Shop of TDD HorrorsFITC
 

Viewers also liked (20)

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

Similar to Fitc whats new in es6 for web devs

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 DevsRami Sayar
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra Sencha
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
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 ComeCory Forsyth
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
Moving to modules
Moving to modulesMoving to modules
Moving to modulesSean Mize
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)David Atchley
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesJamund Ferguson
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESMIgalia
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 

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

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
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
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
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Moving to modules
Moving to modulesMoving to modules
Moving to modules
 
Es6 to es5
Es6 to es5Es6 to es5
Es6 to es5
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
es6
es6es6
es6
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESM
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Intro to React
Intro to ReactIntro to React
Intro to React
 

More from FITC

Cut it up
Cut it upCut it up
Cut it upFITC
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital HealthFITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript PerformanceFITC
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech StackFITC
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR ProjectFITC
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerFITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryFITC
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday InnovationFITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight WebsitesFITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is TerrifyingFITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanFITC
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)FITC
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameFITC
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare SystemFITC
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignFITC
 
The Power of Now
The Power of NowThe Power of Now
The Power of NowFITC
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAsFITC
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstackFITC
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFITC
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForFITC
 

More from FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
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.
  • 4.
  • 5.
  • 6.
  • 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:
  • 10.
  • 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))
  • 13.
  • 14.
  • 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'
  • 16.
  • 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'
  • 23.
  • 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;
  • 29.
  • 30.
  • 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…
  • 39.
  • 40.
  • 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; }
  • 46.
  • 47. var koa = require('koa'); var app = koa(); app.use(function *(){ this.body = 'Hello World'; }); app.listen(3000);
  • 48.
  • 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.
  • 51.
  • 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.