Node's promise chain call

var bPromise = new Promise(function (resolve) {
    console.log('start');
    resolve(100);
});
bPromise.then(function (value) {
    return value * 2;
}).then(function (value) {
    return value * 2;
}).then(function (value) {
    console.log("2: " + value); // => 100 * 2 * 2
});


The output is as follows:
start
2: 400

The above code looks like, the function in the promise is executed only once (only one start output), even if there are multiple thens.
It does, and here's why:
every promise object that executes then is a new object! A new object is returned from the previous then.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326600941&siteId=291194637