ES6 Promise
This code deserves a better detailed explanation, step by step. I have never used this kind of thing before and I wonder in what cases it can be useful. say it's more readable .. heuuu lol. Maybe with the braces in colone, it's a little more readable. _________________________________________________________________________ function asyncFunc(work) { return new Promise(function(resolve, reject) { if (work === "") reject(Error("Nothing")); setTimeout(function() { resolve(work); }, 1000); }); } asyncFunc("Work 1") // Task 1 ***************** >Step 1 .then(function(result) // { console.log(result); return asyncFunc("Work 2"); // Task 2 }, function(error) { console.log(error); }) .then(function(result) { console.log(result); }, function(error) { console.log(error); }); console.log("End"); _______________________________________________________________________ Question: promise is natif object ? Anyway, I hope I never need it