If a then
handler has no return
statement, the resulting chained promise takes on the value undefined
in bluebird. But I cannot see anywhere that it is specified in Promises/A+ or anywhere? Can this behavior be counted on?
Here's a test program:
var Promise = require('bluebird');
var p = Promise.resolve('test');
p.then(function(s) {
console.log('s1='+s);
// no return
}).then(function(s) {
// bluebird prints "undefined". is this specified by a standard?
console.log('s2='+s);
});
Promises/A+ specifies to use the return value of a callback to resolve the promise.
Every function call that doesn't throw
an exception (that has a "normal completion", in spec terms) does have such a return value. If a function execution doesn't encounter a return
statement, this value will be undefined
. This is made explicit in the spec in section 9.2.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With