javascript中的扁平化承诺
bluebird库似乎自动使用了javascript中的扁平化承诺,javascript,promise,ecmascript-6,es6-promise,Javascript,Promise,Ecmascript 6,Es6 Promise,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); // => `
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)
});
这是es6承诺API的合同吗?例如,我看不到有人提到这种扁平化行为
这是es6承诺API的合同吗
是的,它是由建立的合同,并且已经从那里进入ES6规范。你会发现一些讨论,而且。嗯,那些文档非常稀少。MSDN甚至没有提到然后返回一个承诺:-/