SlideShare a Scribd company logo
ES6 ES2015 is Beautiful
Agenda
Go through ES6 features
Look at random cute animal pics
Let(me be!)
var x = 5; let x = 5;
if (1) {
let x = 20;
}
console.log(x);
if (1) {
var x = 20;
}
console.log(x);
Block Scope
Usage
Let
for (var i=0; i<5; i++) {
setTimeout( function() {
console.log(i);
}, 100);
}
for (var i=0; i<5; i++) {
(function (scopedI){
setTimeout( function() {
console.log(scopedI);
}, 100);
})(i);
}
for (let i=0; i<5; i++) {
setTimeout( function() {
console.log(i);
}, 100);
}
Avoid Crazy bugs
(no) Strings (attached)
var name = 'Monika';
console.log('My name is ' + name);
let name2 = 'Monika';
console.log(`My name is ${name2}`);
var str = 'Template strings providen' +
'syntactic sugar forn' +
'constructing strings.';
let str2 = `Template strings provide
syntactic sugar for
constructing strings.`
Variable Bindings
Multiline Strings
Strings
const headline = 'Yahoo products are beautiful.'
headline.startsWith('Yahoo')
// true
headline.endsWith('beautiful')
// true
headline.includes('products')
// true
headline.includes('.')
// false
headline.repeat(2);
//Yahoo products are beautiful.Yahoo products are beautiful.
More
awesomeness!
Arrays
var divsArray = [].slice.call(document.querySelectorAll('div'));
divsArray.forEach(function(node) {
console.log(node);
});
let divs = document.querySelectorAll('div');
Array.from(divs).forEach(node => {
console.log(node);
});
var names = ["Monika", "Seth", "Nikhil", "Mallika"];
var res = names.filter(function (name) {
return name === "Monika"; }
)[0];
let names2 = ["Monika", "Seth", "Nikhil", "Mallika"];
let res2 = names.find(function (name) {
return name === "Monika"; }
);
Array like
Find one element
Function Shorthand
var fun = function() {
console.log('Yay!')
};
let fun2 = () => console.log('Yay!');
var nums = [1,2,3,4,5];
var numsPlus2 =
nums.map(function(num) {
return num + 2;
});
var nums2 = [1,2,3,4,5];
var nums2Plus2 = nums.map(num => num + 2);
Usage
Awesomeness
Function Shorthand
this.x = 42;
setTimeout( function(){
console.log(this.x);
}, 100);
this.x = 42;
var self = this;
setTimeout( function(){
console.log(self.x);
}, 100);
this.x = 42;
setTimeout(() => console.log(this.x), 100);
More Awesomeness
Function Parameters - default
function f(x, y) {
if (!y) {
y = 1;
}
return x * y;
}
function f(x, y) {
// y is 12 if not passed (or passed as undefined)
if (typeof y === 'undefined') {
y = 1;
}
return x * y;
}
function f(x, y=1) {
return x * y;
}
Function Parameters - Spread...
var nums = [9,10,2];
Math.max(...nums);
var nums = [9,10,2];
Math.max(nums);
var nums = [9,10,2];
Math.max.apply(null, nums);
Function Parameters - Rest...
function join(sep, ...nums) {
return nums.join(sep);
}
function join(sep) {
var args = [].slice.call(arguments, 1);
return args.join(sep);
}
join(':', 1, 2, 3);
join(':', 1, 2);
Object (of my affection) - Destructuring
const { user, post } = this.props;var user = this.props.user,
post = this.props.post;
function fun({x, y, z=100}) {
return x + y + z;
}
fun({x:3, y:2}); // 105
function fun(data) {
return data.x + data.y;
}
fun({x:3, y:2});
function fun({x,y}) {
return x + y;
}
fun({x:3, y:2});
Destructuring with
default params
Objects Literals Extension
var obj = {
// defining prototype on object creation
__proto__: theProtoObj,
// shortcut for ‘handler: handler’
handler,
// shortcut for methods - 'toString: function() {}'
toString() {
// base class method call with 'super'
return 'd ' + super.toString();
},
// dynamic property names
[ 'prop_' + (() => 42)() ]: 42
};
(Very) Class(ey)
var Shape = function (id, x, y) {
this.id = id;
this.move(x, y);
};
Shape.prototype.move = function (x, y) {
this.x = x;
this.y = y;
};
class Shape {
constructor (id, x, y) {
this.id = id
this.move(x, y)
}
move (x, y) {
this.x = x
this.y = y
}
}
Class Inheritance
var Rectangle = function (id, x, y, width, height) {
Shape.call(this, id, x, y);
this.width = width;
this.height = height;
};
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;
class Rectangle extends Shape {
constructor (id, x, y, width, height) {
super(id, x, y)
this.width = width
this.height = height
}
}
Promise (me, you will come back..)
function timeout(duration = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
})
}
var p = timeout(1000).then(() => {
console.log('Done after 1000 sec');
});
var request = require('request');
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function foo(finalCallback) {
request.get(url1, function(err1, res1) {
if (err1) { return finalCallback(err1); }
request.post(url2, function(err2, res2) {
if (err2) { return finalCallback(err2); }
request.put(url3, function(err3, res3) {
if (err3) { return finalCallback(err3); }
request.del(url4, function(err4, res4) {
// let's stop here
if (err4) { return finalCallback(err4); }
finalCallback(null, "whew all done");
})
})
})
})
}
// use that function somewhere
foo(function(err, message) {
if (err) {
return console.log("error!", err);
}
console.log("success!", message);
});
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function foo() {
return request.getAsync(url1)
.then(function(res1) {
return request.postAsync(url2);
}).then(function(res2) {
return request.putAsync(url3);
}).then(function(res3) {
return request.delAsync(url4);
}).then(function(res4) {
return "whew all done";
});
}
// use that function somewhere
foo().then(function(message) {
console.log("success!", message);
}).catch(function(err) {
console.log("error!", err);
});
Promise
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1,
url4=url1;
async function foo() {
var res1 = await request.getAsync(url1);
var res2 = await request.getAsync(url2);
var res3 = await request.getAsync(url3);
var res4 = await request.getAsync(url4);
return "whew all done";
}
// use that function somewhere
foo().then(function(message) {
console.log("success!", message);
}).catch(function(err) {
console.log("error!", err);
});
Async/ Await - Glimpse
So much more..
Modules
Proxy
Generator, Iterator
Maps, Sets
Proxy
Symbols
More...
Browser compatible?
Javascript compiler
Use Next Generation Javascript Today!
http://babeljs.io/
Babel
Quick Demo
Using babel-cli
Presets
Pubs presets
npm install --save-dev babel-cli
babel test.js
ynpm install --save-dev babel-preset-pubs
babel test.js --presets=pubs
// Use .babelrc
Links
https://yo/es6beauty
http://www.ecma-international.org/ecma-262/6.0/
http://es6-features.org
https://babeljs.io/
QnA

More Related Content

What's hot

Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 

What's hot (20)

Csharp_Chap13
Csharp_Chap13Csharp_Chap13
Csharp_Chap13
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84The Ring programming language version 1.2 book - Part 40 of 84
The Ring programming language version 1.2 book - Part 40 of 84
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84
 
Promise is a Promise
Promise is a PromisePromise is a Promise
Promise is a Promise
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Acm
AcmAcm
Acm
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88The Ring programming language version 1.3 book - Part 46 of 88
The Ring programming language version 1.3 book - Part 46 of 88
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 

Similar to ES6(ES2015) is beautiful

深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
jeffz
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
jeffz
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)
Will Kurt
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programming
jeffz
 

Similar to ES6(ES2015) is beautiful (20)

Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
 
Javascript
JavascriptJavascript
Javascript
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)Intro to Functional Programming Workshop (code4lib)
Intro to Functional Programming Workshop (code4lib)
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Monadologie
MonadologieMonadologie
Monadologie
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programming
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 

ES6(ES2015) is beautiful

  • 1. ES6 ES2015 is Beautiful
  • 2. Agenda Go through ES6 features Look at random cute animal pics
  • 3.
  • 4. Let(me be!) var x = 5; let x = 5; if (1) { let x = 20; } console.log(x); if (1) { var x = 20; } console.log(x); Block Scope Usage
  • 5. Let for (var i=0; i<5; i++) { setTimeout( function() { console.log(i); }, 100); } for (var i=0; i<5; i++) { (function (scopedI){ setTimeout( function() { console.log(scopedI); }, 100); })(i); } for (let i=0; i<5; i++) { setTimeout( function() { console.log(i); }, 100); } Avoid Crazy bugs
  • 6.
  • 7. (no) Strings (attached) var name = 'Monika'; console.log('My name is ' + name); let name2 = 'Monika'; console.log(`My name is ${name2}`); var str = 'Template strings providen' + 'syntactic sugar forn' + 'constructing strings.'; let str2 = `Template strings provide syntactic sugar for constructing strings.` Variable Bindings Multiline Strings
  • 8. Strings const headline = 'Yahoo products are beautiful.' headline.startsWith('Yahoo') // true headline.endsWith('beautiful') // true headline.includes('products') // true headline.includes('.') // false headline.repeat(2); //Yahoo products are beautiful.Yahoo products are beautiful. More awesomeness!
  • 9.
  • 10. Arrays var divsArray = [].slice.call(document.querySelectorAll('div')); divsArray.forEach(function(node) { console.log(node); }); let divs = document.querySelectorAll('div'); Array.from(divs).forEach(node => { console.log(node); }); var names = ["Monika", "Seth", "Nikhil", "Mallika"]; var res = names.filter(function (name) { return name === "Monika"; } )[0]; let names2 = ["Monika", "Seth", "Nikhil", "Mallika"]; let res2 = names.find(function (name) { return name === "Monika"; } ); Array like Find one element
  • 11.
  • 12. Function Shorthand var fun = function() { console.log('Yay!') }; let fun2 = () => console.log('Yay!'); var nums = [1,2,3,4,5]; var numsPlus2 = nums.map(function(num) { return num + 2; }); var nums2 = [1,2,3,4,5]; var nums2Plus2 = nums.map(num => num + 2); Usage Awesomeness
  • 13. Function Shorthand this.x = 42; setTimeout( function(){ console.log(this.x); }, 100); this.x = 42; var self = this; setTimeout( function(){ console.log(self.x); }, 100); this.x = 42; setTimeout(() => console.log(this.x), 100); More Awesomeness
  • 14.
  • 15. Function Parameters - default function f(x, y) { if (!y) { y = 1; } return x * y; } function f(x, y) { // y is 12 if not passed (or passed as undefined) if (typeof y === 'undefined') { y = 1; } return x * y; } function f(x, y=1) { return x * y; }
  • 16. Function Parameters - Spread... var nums = [9,10,2]; Math.max(...nums); var nums = [9,10,2]; Math.max(nums); var nums = [9,10,2]; Math.max.apply(null, nums);
  • 17. Function Parameters - Rest... function join(sep, ...nums) { return nums.join(sep); } function join(sep) { var args = [].slice.call(arguments, 1); return args.join(sep); } join(':', 1, 2, 3); join(':', 1, 2);
  • 18.
  • 19. Object (of my affection) - Destructuring const { user, post } = this.props;var user = this.props.user, post = this.props.post; function fun({x, y, z=100}) { return x + y + z; } fun({x:3, y:2}); // 105 function fun(data) { return data.x + data.y; } fun({x:3, y:2}); function fun({x,y}) { return x + y; } fun({x:3, y:2}); Destructuring with default params
  • 20. Objects Literals Extension var obj = { // defining prototype on object creation __proto__: theProtoObj, // shortcut for ‘handler: handler’ handler, // shortcut for methods - 'toString: function() {}' toString() { // base class method call with 'super' return 'd ' + super.toString(); }, // dynamic property names [ 'prop_' + (() => 42)() ]: 42 };
  • 21.
  • 22. (Very) Class(ey) var Shape = function (id, x, y) { this.id = id; this.move(x, y); }; Shape.prototype.move = function (x, y) { this.x = x; this.y = y; }; class Shape { constructor (id, x, y) { this.id = id this.move(x, y) } move (x, y) { this.x = x this.y = y } }
  • 23. Class Inheritance var Rectangle = function (id, x, y, width, height) { Shape.call(this, id, x, y); this.width = width; this.height = height; }; Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; class Rectangle extends Shape { constructor (id, x, y, width, height) { super(id, x, y) this.width = width this.height = height } }
  • 24.
  • 25. Promise (me, you will come back..) function timeout(duration = 0) { return new Promise((resolve, reject) => { setTimeout(resolve, duration); }) } var p = timeout(1000).then(() => { console.log('Done after 1000 sec'); });
  • 26. var request = require('request'); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; function foo(finalCallback) { request.get(url1, function(err1, res1) { if (err1) { return finalCallback(err1); } request.post(url2, function(err2, res2) { if (err2) { return finalCallback(err2); } request.put(url3, function(err3, res3) { if (err3) { return finalCallback(err3); } request.del(url4, function(err4, res4) { // let's stop here if (err4) { return finalCallback(err4); } finalCallback(null, "whew all done"); }) }) }) }) } // use that function somewhere foo(function(err, message) { if (err) { return console.log("error!", err); } console.log("success!", message); }); var Promise = require('bluebird'); var request = Promise.promisifyAll(require('request')); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; function foo() { return request.getAsync(url1) .then(function(res1) { return request.postAsync(url2); }).then(function(res2) { return request.putAsync(url3); }).then(function(res3) { return request.delAsync(url4); }).then(function(res4) { return "whew all done"; }); } // use that function somewhere foo().then(function(message) { console.log("success!", message); }).catch(function(err) { console.log("error!", err); }); Promise
  • 27. var Promise = require('bluebird'); var request = Promise.promisifyAll(require('request')); var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; async function foo() { var res1 = await request.getAsync(url1); var res2 = await request.getAsync(url2); var res3 = await request.getAsync(url3); var res4 = await request.getAsync(url4); return "whew all done"; } // use that function somewhere foo().then(function(message) { console.log("success!", message); }).catch(function(err) { console.log("error!", err); }); Async/ Await - Glimpse
  • 28. So much more.. Modules Proxy Generator, Iterator Maps, Sets Proxy Symbols More...
  • 29.
  • 30. Browser compatible? Javascript compiler Use Next Generation Javascript Today! http://babeljs.io/ Babel Quick Demo Using babel-cli Presets Pubs presets npm install --save-dev babel-cli babel test.js ynpm install --save-dev babel-preset-pubs babel test.js --presets=pubs // Use .babelrc
  • 32. QnA

Editor's Notes

  1. My favorite part