Javascript 使用Bluebird链接结果

Javascript 使用Bluebird链接结果,javascript,bluebird,Javascript,Bluebird,在解析链中,每个元素的输入都是前一个元素的解析值(除非它不是函数),是否有任何方便的方法 我试图将以下逻辑链接到一个方法中: function getClient() { // resolves with the client } function getClientProduct(client) { // resolves with the product } var response = {}; // global response object; function p

在解析链中,每个元素的输入都是前一个元素的解析值(除非它不是函数),是否有任何方便的方法

我试图将以下逻辑链接到一个方法中:

function getClient() {
    // resolves with the client
}

function getClientProduct(client) {
    // resolves with the product
}

var response = {}; // global response object;

function prepareResponse(product) {
    // prepares global response object, resolves with `undefined`
}

promise.someMethod(getClient, getClientProduct, prepareResponse, response)
    .then(data=> {
        // data = the response object;
    });
我希望避免写以下内容(如果可能):


那些箭头函数没有意义。你可以做得很简单

getClient().then(getClientProduct).then(prepareResponse).…
没有方便的方法可以进一步缩短,我想你不想考虑

[getClient, getClientProduct, prepareResponse].reduce((p,fn)=>p.then(fn), Promise.resolve())

对于最后一个,您可以使用。

这些箭头函数没有意义。你可以做得很简单

getClient().then(getClientProduct).then(prepareResponse).…
没有方便的方法可以进一步缩短,我想你不想考虑

[getClient, getClientProduct, prepareResponse].reduce((p,fn)=>p.then(fn), Promise.resolve())

对于最后一种方法,您可以使用。

您实际上并不需要一种方便的方法。你可以这样写:

function getClient() {
    // resolves with the client
}

function getClientProduct(client) {
    // resolves with the product
}

var response = {}; // global response object;

function prepareResponse(product) {
    // prepares global response object, resolves with `undefined`
}

getClient()
    .then(getClientProduct)
    .then(prepareResponse)
    .return(response);

你真的不需要一个方便的方法。你可以这样写:

function getClient() {
    // resolves with the client
}

function getClientProduct(client) {
    // resolves with the product
}

var response = {}; // global response object;

function prepareResponse(product) {
    // prepares global response object, resolves with `undefined`
}

getClient()
    .then(getClientProduct)
    .then(prepareResponse)
    .return(response);

好的,谢谢!我想我错过了一些东西,因为这将是一个很好的功能;)好的,谢谢!我想我错过了一些东西,因为这将是一个很好的功能;)