What is the meaning of resolving a chain promise if then the handler returns nothing?

If a thenhandler does not have an instruction return, the resulting whole promise takes a value undefinedin bluebird. But I do not see anywhere that it is indicated in Promises / A + or anywhere? Can this behavior be calculated?

Here's the 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);
});
+4
source share
2 answers

Promises / A + indicates the use of the callback return value to resolve the promise.

, throw ( " ", spec-), . return, undefined. 9.2.1.

+5

, bluebird. , undefined, JS.

" JS". .

+2

Source: https://habr.com/ru/post/1627179/


All Articles