SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
I want my ES6, like ES.NOWI want my ES6, like ES.NOW
Ken Rimple Mentor, Trainer, Consultant Chariot
Solutions
Slides - <-- that's not a zerohttp://1drv.ms/1DJQ4RO
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
1 of 43 04/10/2015 06:04 PM
TopicsTopics
What is ES6?
Where are we now?
How can we code ES6 now and run in ES5?
Client-side
Server-side
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
2 of 43 04/10/2015 06:04 PM
What is ES6?What is ES6?
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
3 of 43 04/10/2015 06:04 PM
ECMASCRIPT 6ECMASCRIPT 6
The next evolution of JavaScript (ECMASCRIPT === ES)
Being embedded in browsers within the next 18
months
Lots of new features
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
4 of 43 04/10/2015 06:04 PM
Major new featuresMajor new features
Classes, extends, constructors and member functions
class Klingon extends Warrior {
constructor(name) { }
methodA();
methodB();
}
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
5 of 43 04/10/2015 06:04 PM
Local variables, constantsLocal variables, constants
function foo() {
// function-scoped
var x = 234;
if (x === 234) {
let b = 24; // scoped to if
}
}
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
6 of 43 04/10/2015 06:04 PM
Arrow functions and string magicArrow functions and string magic
myArray.forEach((val) =>
console.log(`${val.a} - ${val.b}`);
var longStr = `
This is a long
string with
multiple lines`;
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
7 of 43 04/10/2015 06:04 PM
Default and "rest" parameters to functionsDefault and "rest" parameters to functions
function foo(a = 234, ...b) {
console.log(a);
for (ele of b) {
console.log(ele);
}
}
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
8 of 43 04/10/2015 06:04 PM
DestructuringDestructuring
Pull out parts of an object into variables
let a = { b: 'c', d: 'e' };
let {b, d} = a;
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
9 of 43 04/10/2015 06:04 PM
Better collectionsBetter collections
let keys = new Set();
keys.add(1); keys.add(2);
keys.has(3) // false
keys.has(1) // true
let map = new Map();
map.set('a', 123);
map.set('b', 'foobarbaz');
map.has('a') // true
map.get('a') // 123
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
10 of 43 04/10/2015 06:04 PM
Promises (native to JS!)Promises (native to JS!)
Called API:
return new Promise((resolve, reject) => {
resolve(answer);
// error condition
reject(errorData);
}
Caller:
apiCall.then(
(answer) => { ... },
(error) => { ... }
});
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
11 of 43 04/10/2015 06:04 PM
GeneratorsGenerators
function *shoppingList() {
yield 'apples';
yield 'oranges';
yield 'cereal';
}
let iterator = shoppingList();
while(true) {
var obj = iterator.next();
if (obj.done) break;
console.log(obj.value);
}
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
12 of 43 04/10/2015 06:04 PM
What is supported now?What is supported now?
See
Browser-side - not everything natively - unless
you're on Firefox Nightly
Or you can use transpilers, shims and/or a build
process
Server-side - depends on engine
http://kangax.github.io/compat-table/es6/
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
13 of 43 04/10/2015 06:04 PM
ES6 in the Browser...ES6 in the Browser...
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
14 of 43 04/10/2015 06:04 PM
What about today?What about today?
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
15 of 43 04/10/2015 06:04 PM
Let's move the enterprise to that NOW!Let's move the enterprise to that NOW!
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
16 of 43 04/10/2015 06:04 PM
How else? Two major themesHow else? Two major themes
Dynamic run-time translation
Transpiling (translation compiling) to generate source
(or source + library references)
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
17 of 43 04/10/2015 06:04 PM
TranspilersTranspilers
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
18 of 43 04/10/2015 06:04 PM
BabelBabel
Has many flags and options
Very configurable
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
19 of 43 04/10/2015 06:04 PM
Babel interactive APIBabel interactive API
< script src="lib/browser.js"></ script>
< script src="lib/browser-polyfill.js"></ script>
< script src="lib/shim.js"></ script>
Now you can mount scripts with type of text/babel
and they will be transpiled
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
20 of 43 04/10/2015 06:04 PM
Approach not quite recommended...Approach not quite recommended...
Babel is meant to be run as part of a build
Not all features work in a dynamic mode (modules,
etc.)
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
21 of 43 04/10/2015 06:04 PM
Babel command lineBabel command line
$ npm install -g babel
$ babel foo.js
// output returned inline
Better yet, you should use a build system
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
22 of 43 04/10/2015 06:04 PM
Build optionsBuild options
Build-based transformer plugin (gulp-babel)
Browserify with babel plugin
Karma with pre-processor
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
23 of 43 04/10/2015 06:04 PM
Babel Gulp project demoBabel Gulp project demo
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
24 of 43 04/10/2015 06:04 PM
Code transformers supportedCode transformers supported
Use --help to return list of transformers
$ babel --help
Transformers:
- [asyncToGenerator]
- [bluebirdCoroutines]
- es3.memberExpressionLiterals
- es3.propertyLiterals
- es5.properties.mutators
...
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
25 of 43 04/10/2015 06:04 PM
Adding or removing transformersAdding or removing transformers
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
26 of 43 04/10/2015 06:04 PM
Babel has a set of default and optional transformers
Blacklist normally included transformers to remove
Whitelist - only these transformers are executed
Concept - remove transpiler features as browsers
support them - reality? Maybe not or complex build
targeting each browser supported...
babel --blacklist=es6.spread,
es6.regex.unicode foo.js
babel --whitelist=es6.classes,es6.forOf
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
27 of 43 04/10/2015 06:04 PM
TraceurTraceur
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
28 of 43 04/10/2015 06:04 PM
Using Traceur in the browserUsing Traceur in the browser
< script src=".../traceur.js">< /script>
< script src=".../bootstrap.js">< /script>
< script type="module">
Your ES6 code here...
< /script>
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
29 of 43 04/10/2015 06:04 PM
Traceur in a buildTraceur in a build
You can use
tracer as a command-line utility
traceur-gulp (|grunt|whatever)
6to5ify with Browserify
Karma traceur preprocessor
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
30 of 43 04/10/2015 06:04 PM
Some challengesSome challenges
Generated ES5 code is not always correct
The transpiler cannot know all API changes by itself
Example - Array methods
from is an ES6 feature in Array, but was not included
in the transpiler directly.
Babel provides a polyfill for this - polyfill.js - in
the library
Array.from({length: 5}, (v, k) => k);
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
31 of 43 04/10/2015 06:04 PM
Transpiling is not a panaceaTranspiling is not a panacea
You need to pick a module loader strategy to transpile
down to
You need to re-test once browsers begin to support
features
Some ES6 features (tail-recursion) will require binary
browser changes
Some APIs won't be available without polyfills
Check sites like Kangax
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
32 of 43 04/10/2015 06:04 PM
Where are we heading?Where are we heading?
Angular 2.0 - will use the traceur compiler + AtScript
(===> Typescript 1.5)
Typescript 1.5 - will generate ES5 AND ES6, contain
AtScript annotationes
Ember 2 - will use ES6 coding features (with Babel)
EVENTUALLY - ES6 rules them all
But we thought that with HTML5 too
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
33 of 43 04/10/2015 06:04 PM
Server-side ECMAScript 6Server-side ECMAScript 6
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
34 of 43 04/10/2015 06:04 PM
Several Options hereSeveral Options here
NodeJS with a transpiler to ES5 (see prior examples)
NodeJS with a wrapper such as node-babel
NodeJS activating Harmony features directly
io.js (fork of NodeJS)
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
35 of 43 04/10/2015 06:04 PM
NodeJS and ECMAScript 6 features w/BabelNodeJS and ECMAScript 6 features w/Babel
Just install Babel or
Run node-babel
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
36 of 43 04/10/2015 06:04 PM
NodeJS and ECMAScript 6NodeJS and ECMAScript 6
You can enable ES6 features
Much of ES6 is implemented
You must turn on special flags
$ node --v8-options | grep "harmony"
--harmony_scoping (enable harmony block scoping)
--harmony_modules (enable harmony modules
(implies block scoping))
--harmony_generators (enable harmony generators)
--harmony_strings (enable harmony string)
--harmony_arrays (enable harmony arrays)
...
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
37 of 43 04/10/2015 06:04 PM
WelcomeWelcome babel-nodebabel-node
Runs Node with a Babel shim
babel-node
> myfunc = () => console.log('hiya!');
> myfunc();
hiya!
All ES6 harmony flags supported as of 5.0.8
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
38 of 43 04/10/2015 06:04 PM
ES6 Node server exampleES6 Node server example
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
39 of 43 04/10/2015 06:04 PM
Alternative to NodeJs - io.jsAlternative to NodeJs - io.js
A fork of node.js
Updated status https://github.com/iojs/io.js
/issues/1336
Controversial, but has a number of developers focused
on moving the platform forward
Already supports a number of ES6 features out of the
box, can turn on the rest
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
40 of 43 04/10/2015 06:04 PM
ES6-ready framework exampleES6-ready framework example
Koa - developer of Express - uses --harmony flag
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
41 of 43 04/10/2015 06:04 PM
Should you do this now?Should you do this now?
Up to you
Specs will be tweaked
Do NOT dive in and use every feature without
weighing it
You can still code "Good Parts" style
But Crockford has a video on the newer "Good Parts"
of ES6
Link: http://goo.gl/eD4UB5
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
42 of 43 04/10/2015 06:04 PM
ResourcesResources
Traceur -
Babel -
Slides - <-- that's not a zero
https://github.com/google/traceur-compiler
https://babeljs.io
http://1drv.ms/1DJQ4RO
reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/
43 of 43 04/10/2015 06:04 PM

Contenu connexe

Tendances

JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...0xdaryl
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Codemotion
 
Swagger AEM - An OpenAPI Specification for AEM
Swagger AEM - An OpenAPI Specification for AEMSwagger AEM - An OpenAPI Specification for AEM
Swagger AEM - An OpenAPI Specification for AEMCliffano Subagio
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency HeavenOpusVL
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebookGeeks Anonymes
 

Tendances (10)

Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Swagger AEM - An OpenAPI Specification for AEM
Swagger AEM - An OpenAPI Specification for AEMSwagger AEM - An OpenAPI Specification for AEM
Swagger AEM - An OpenAPI Specification for AEM
 
CakePHP
CakePHPCakePHP
CakePHP
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency Heaven
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebook
 
Troubleshooting Puppet
Troubleshooting PuppetTroubleshooting Puppet
Troubleshooting Puppet
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Perl
PerlPerl
Perl
 

Similaire à KenRimple_ETE2015_ES6LikeNow

MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0Thomas Conté
 
Jazoon2010 - Edgar Silva - Open source SOA on Steroids
Jazoon2010 - Edgar Silva - Open source SOA on SteroidsJazoon2010 - Edgar Silva - Open source SOA on Steroids
Jazoon2010 - Edgar Silva - Open source SOA on SteroidsEdgar Silva
 
What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018Jeff Smith
 
Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoringOracle Korea
 
Spring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringSpring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringDonghuKIM2
 
How to measure everything - a million metrics per second with minimal develop...
How to measure everything - a million metrics per second with minimal develop...How to measure everything - a million metrics per second with minimal develop...
How to measure everything - a million metrics per second with minimal develop...Jos Boumans
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patternsukdpe
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalHimanshu Mendiratta
 
Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4 Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4 Lars Vogel
 
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaas
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaasApiOps Tampere meetup 17.11.2017- serverless_with_openfaas
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaasSakari Hoisko
 
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17GreeceJS
 
Employee Info Starter Kit
Employee Info Starter KitEmployee Info Starter Kit
Employee Info Starter Kitjoycsc
 
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetes
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetesSpryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetes
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetesBernd Alter
 
Java Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIRJava Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIRMatthias Reining
 

Similaire à KenRimple_ETE2015_ES6LikeNow (20)

Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
 
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
 
Jazoon2010 - Edgar Silva - Open source SOA on Steroids
Jazoon2010 - Edgar Silva - Open source SOA on SteroidsJazoon2010 - Edgar Silva - Open source SOA on Steroids
Jazoon2010 - Edgar Silva - Open source SOA on Steroids
 
URL Design
URL DesignURL Design
URL Design
 
What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018What's New in Oracle SQL Developer for 2018
What's New in Oracle SQL Developer for 2018
 
Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoring
 
Spring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringSpring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics Monitoring
 
How to measure everything - a million metrics per second with minimal develop...
How to measure everything - a million metrics per second with minimal develop...How to measure everything - a million metrics per second with minimal develop...
How to measure everything - a million metrics per second with minimal develop...
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
C# 4.0 - Whats New
C# 4.0 - Whats NewC# 4.0 - Whats New
C# 4.0 - Whats New
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patterns
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
 
Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4 Eclipse 40 and Eclipse e4
Eclipse 40 and Eclipse e4
 
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaas
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaasApiOps Tampere meetup 17.11.2017- serverless_with_openfaas
ApiOps Tampere meetup 17.11.2017- serverless_with_openfaas
 
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
 
Employee Info Starter Kit
Employee Info Starter KitEmployee Info Starter Kit
Employee Info Starter Kit
 
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetes
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetesSpryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetes
Spryker meetup-distribute-your-spryker-deployment-with-docker-and-kubernetes
 
Java Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIRJava Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIR
 

KenRimple_ETE2015_ES6LikeNow

  • 1. I want my ES6, like ES.NOWI want my ES6, like ES.NOW Ken Rimple Mentor, Trainer, Consultant Chariot Solutions Slides - <-- that's not a zerohttp://1drv.ms/1DJQ4RO reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 1 of 43 04/10/2015 06:04 PM
  • 2. TopicsTopics What is ES6? Where are we now? How can we code ES6 now and run in ES5? Client-side Server-side reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 2 of 43 04/10/2015 06:04 PM
  • 3. What is ES6?What is ES6? reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 3 of 43 04/10/2015 06:04 PM
  • 4. ECMASCRIPT 6ECMASCRIPT 6 The next evolution of JavaScript (ECMASCRIPT === ES) Being embedded in browsers within the next 18 months Lots of new features reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 4 of 43 04/10/2015 06:04 PM
  • 5. Major new featuresMajor new features Classes, extends, constructors and member functions class Klingon extends Warrior { constructor(name) { } methodA(); methodB(); } reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 5 of 43 04/10/2015 06:04 PM
  • 6. Local variables, constantsLocal variables, constants function foo() { // function-scoped var x = 234; if (x === 234) { let b = 24; // scoped to if } } reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 6 of 43 04/10/2015 06:04 PM
  • 7. Arrow functions and string magicArrow functions and string magic myArray.forEach((val) => console.log(`${val.a} - ${val.b}`); var longStr = ` This is a long string with multiple lines`; reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 7 of 43 04/10/2015 06:04 PM
  • 8. Default and "rest" parameters to functionsDefault and "rest" parameters to functions function foo(a = 234, ...b) { console.log(a); for (ele of b) { console.log(ele); } } reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 8 of 43 04/10/2015 06:04 PM
  • 9. DestructuringDestructuring Pull out parts of an object into variables let a = { b: 'c', d: 'e' }; let {b, d} = a; reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 9 of 43 04/10/2015 06:04 PM
  • 10. Better collectionsBetter collections let keys = new Set(); keys.add(1); keys.add(2); keys.has(3) // false keys.has(1) // true let map = new Map(); map.set('a', 123); map.set('b', 'foobarbaz'); map.has('a') // true map.get('a') // 123 reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 10 of 43 04/10/2015 06:04 PM
  • 11. Promises (native to JS!)Promises (native to JS!) Called API: return new Promise((resolve, reject) => { resolve(answer); // error condition reject(errorData); } Caller: apiCall.then( (answer) => { ... }, (error) => { ... } }); reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 11 of 43 04/10/2015 06:04 PM
  • 12. GeneratorsGenerators function *shoppingList() { yield 'apples'; yield 'oranges'; yield 'cereal'; } let iterator = shoppingList(); while(true) { var obj = iterator.next(); if (obj.done) break; console.log(obj.value); } reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 12 of 43 04/10/2015 06:04 PM
  • 13. What is supported now?What is supported now? See Browser-side - not everything natively - unless you're on Firefox Nightly Or you can use transpilers, shims and/or a build process Server-side - depends on engine http://kangax.github.io/compat-table/es6/ reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 13 of 43 04/10/2015 06:04 PM
  • 14. ES6 in the Browser...ES6 in the Browser... reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 14 of 43 04/10/2015 06:04 PM
  • 15. What about today?What about today? reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 15 of 43 04/10/2015 06:04 PM
  • 16. Let's move the enterprise to that NOW!Let's move the enterprise to that NOW! reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 16 of 43 04/10/2015 06:04 PM
  • 17. How else? Two major themesHow else? Two major themes Dynamic run-time translation Transpiling (translation compiling) to generate source (or source + library references) reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 17 of 43 04/10/2015 06:04 PM
  • 18. TranspilersTranspilers reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 18 of 43 04/10/2015 06:04 PM
  • 19. BabelBabel Has many flags and options Very configurable reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 19 of 43 04/10/2015 06:04 PM
  • 20. Babel interactive APIBabel interactive API < script src="lib/browser.js"></ script> < script src="lib/browser-polyfill.js"></ script> < script src="lib/shim.js"></ script> Now you can mount scripts with type of text/babel and they will be transpiled reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 20 of 43 04/10/2015 06:04 PM
  • 21. Approach not quite recommended...Approach not quite recommended... Babel is meant to be run as part of a build Not all features work in a dynamic mode (modules, etc.) reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 21 of 43 04/10/2015 06:04 PM
  • 22. Babel command lineBabel command line $ npm install -g babel $ babel foo.js // output returned inline Better yet, you should use a build system reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 22 of 43 04/10/2015 06:04 PM
  • 23. Build optionsBuild options Build-based transformer plugin (gulp-babel) Browserify with babel plugin Karma with pre-processor reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 23 of 43 04/10/2015 06:04 PM
  • 24. Babel Gulp project demoBabel Gulp project demo reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 24 of 43 04/10/2015 06:04 PM
  • 25. Code transformers supportedCode transformers supported Use --help to return list of transformers $ babel --help Transformers: - [asyncToGenerator] - [bluebirdCoroutines] - es3.memberExpressionLiterals - es3.propertyLiterals - es5.properties.mutators ... reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 25 of 43 04/10/2015 06:04 PM
  • 26. Adding or removing transformersAdding or removing transformers reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 26 of 43 04/10/2015 06:04 PM
  • 27. Babel has a set of default and optional transformers Blacklist normally included transformers to remove Whitelist - only these transformers are executed Concept - remove transpiler features as browsers support them - reality? Maybe not or complex build targeting each browser supported... babel --blacklist=es6.spread, es6.regex.unicode foo.js babel --whitelist=es6.classes,es6.forOf reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 27 of 43 04/10/2015 06:04 PM
  • 28. TraceurTraceur reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 28 of 43 04/10/2015 06:04 PM
  • 29. Using Traceur in the browserUsing Traceur in the browser < script src=".../traceur.js">< /script> < script src=".../bootstrap.js">< /script> < script type="module"> Your ES6 code here... < /script> reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 29 of 43 04/10/2015 06:04 PM
  • 30. Traceur in a buildTraceur in a build You can use tracer as a command-line utility traceur-gulp (|grunt|whatever) 6to5ify with Browserify Karma traceur preprocessor reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 30 of 43 04/10/2015 06:04 PM
  • 31. Some challengesSome challenges Generated ES5 code is not always correct The transpiler cannot know all API changes by itself Example - Array methods from is an ES6 feature in Array, but was not included in the transpiler directly. Babel provides a polyfill for this - polyfill.js - in the library Array.from({length: 5}, (v, k) => k); reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 31 of 43 04/10/2015 06:04 PM
  • 32. Transpiling is not a panaceaTranspiling is not a panacea You need to pick a module loader strategy to transpile down to You need to re-test once browsers begin to support features Some ES6 features (tail-recursion) will require binary browser changes Some APIs won't be available without polyfills Check sites like Kangax reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 32 of 43 04/10/2015 06:04 PM
  • 33. Where are we heading?Where are we heading? Angular 2.0 - will use the traceur compiler + AtScript (===> Typescript 1.5) Typescript 1.5 - will generate ES5 AND ES6, contain AtScript annotationes Ember 2 - will use ES6 coding features (with Babel) EVENTUALLY - ES6 rules them all But we thought that with HTML5 too reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 33 of 43 04/10/2015 06:04 PM
  • 34. Server-side ECMAScript 6Server-side ECMAScript 6 reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 34 of 43 04/10/2015 06:04 PM
  • 35. Several Options hereSeveral Options here NodeJS with a transpiler to ES5 (see prior examples) NodeJS with a wrapper such as node-babel NodeJS activating Harmony features directly io.js (fork of NodeJS) reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 35 of 43 04/10/2015 06:04 PM
  • 36. NodeJS and ECMAScript 6 features w/BabelNodeJS and ECMAScript 6 features w/Babel Just install Babel or Run node-babel reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 36 of 43 04/10/2015 06:04 PM
  • 37. NodeJS and ECMAScript 6NodeJS and ECMAScript 6 You can enable ES6 features Much of ES6 is implemented You must turn on special flags $ node --v8-options | grep "harmony" --harmony_scoping (enable harmony block scoping) --harmony_modules (enable harmony modules (implies block scoping)) --harmony_generators (enable harmony generators) --harmony_strings (enable harmony string) --harmony_arrays (enable harmony arrays) ... reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 37 of 43 04/10/2015 06:04 PM
  • 38. WelcomeWelcome babel-nodebabel-node Runs Node with a Babel shim babel-node > myfunc = () => console.log('hiya!'); > myfunc(); hiya! All ES6 harmony flags supported as of 5.0.8 reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 38 of 43 04/10/2015 06:04 PM
  • 39. ES6 Node server exampleES6 Node server example reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 39 of 43 04/10/2015 06:04 PM
  • 40. Alternative to NodeJs - io.jsAlternative to NodeJs - io.js A fork of node.js Updated status https://github.com/iojs/io.js /issues/1336 Controversial, but has a number of developers focused on moving the platform forward Already supports a number of ES6 features out of the box, can turn on the rest reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 40 of 43 04/10/2015 06:04 PM
  • 41. ES6-ready framework exampleES6-ready framework example Koa - developer of Express - uses --harmony flag reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 41 of 43 04/10/2015 06:04 PM
  • 42. Should you do this now?Should you do this now? Up to you Specs will be tweaked Do NOT dive in and use every feature without weighing it You can still code "Good Parts" style But Crockford has a video on the newer "Good Parts" of ES6 Link: http://goo.gl/eD4UB5 reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 42 of 43 04/10/2015 06:04 PM
  • 43. ResourcesResources Traceur - Babel - Slides - <-- that's not a zero https://github.com/google/traceur-compiler https://babeljs.io http://1drv.ms/1DJQ4RO reveal.js - The HTML Presentation Framework http://0.0.0.0:8000/?print-pdf#/ 43 of 43 04/10/2015 06:04 PM