towry
2/27/2015 - 1:16 PM

promise.js

var b = new Promise(function (resolve, reject) { 
  setTimeout(function(){
    reject(new Error("haha"));})
});

b.then(function(v){
  console.log(v); return 3;
}, function(e) {
  console.log("error: " + e);
}).then(function(v){
  console.log("2: " + v);
}, function(e) {
  console.log("error 2: " + e); 
});

// output
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
VM565:2 error: Error: haha
VM565:2 2: undefined