Gerd Teniers
Bart Wullems
ES5.1
ES6
258-page pdf
613-page pdf
x 2.5
readFile("hello.txt",function(err,content){
if(err){
//handle error
}else{
//use content
}
}
ES5
ES6
readFile("hello.txt")
.then(function(content){
//use content
},function(err){
//handle error
});
step1(function(value1){
step2(value1,function(value2){
step3(value2,function(value3){
//do something
});
});
});
ES5
ES6
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(function (value3) {
// Do something
})
.catch(function (error) {
// Handle any error from all above steps
})
.done();
(async function(){
try{
var value1=await step1();
var value2=await step2(value1);
var value3=await step3(value2);
//do something
}catch(error){
//handle any error here
}
}())
ES6
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(function (value3) {
// Do something
})
.catch(function (error) {
// Handle any error from all above steps
})
.done();
ES7
(async function(){
try{
var value1=await step1();
var value2=await step2(value1);
var value3=await step3(value2);
//do something
}catch(error){
//handle any error here
}
}())
ES7
Q.async(function*(){
try{
var value1=yield step1();
var value2=yield step2(value1);
var value3=yield step3(value2);
//do something
}catch(error){
// handle any error here
}
})()
ES6
ECMAScript 6 is a major upgrade to the language
Expect browsers to implement the upgrade gradually
Use ES6 to ES5 compilers to bridge the gap
You can(and should) use ES6 today