【发布时间】:2015-09-15 05:32:19
【问题描述】:
bluebird 库似乎自动将Promise::then 用作 promise 上的“map”和“flatMap”的等价物,例如,请参阅此示例。
var Promise;
Promise = require('bluebird').Promise;
Promise.resolve(1).then(function(x) {
return Promise.resolve(x + 1);
}).then(function(x) {
return console.log(x); // => `2` (not a promise)
});
Promise.resolve(1).then(function(x) {
return x + 1;
}).then(function(x) {
return console.log(x); // => `2`
});
Promise.reject('hi').catch(function(x) {
return Promise.reject('hi2');
}).catch(function(x) {
return console.error(x); // => `hi2` (not a promise)
});
【问题讨论】:
-
呃,那些文档非常稀疏。 MSDN 甚至没有提到
then返回一个承诺:-/
标签: javascript promise ecmascript-6 es6-promise