javascript – 从承诺返回然后()

我有一个像这样的JavaScript代码:

function justTesting() {
  promise.then(function(output) {
    return output + 1;
  });
}

var test = justTesting();

对于var测试,我总是有一个未定义的值.我认为这是因为承诺没有解决喷射……有没有办法从承诺中返回一个价值?

解决方法:

当你从then()回调中返回一些东西时,它有点神奇.如果返回一个值,则使用该值调用next then().但是,如果你返回类似promise的东西,那么next()会等待它,并且仅在该promise承诺(成功/失败)时被调用.

通过https://developers.google.com/web/fundamentals/getting-started/primers/promises#queuing_asynchronous_actions

相关文章

最后的控制台返回空数组.控制台在ids.map函数完成之前运行va...
我正在尝试将rxJava与我已经知道的内容联系起来,特别是来自J...
config.jsconstconfig={base_url_api:"https://douban....
我正在阅读MDN中的javascript,并且遇到了这个谈论承诺并且不...
config.jsconstconfig={base_url_api:"https://douban....
这是我的代码main.cpp:#include<string>#include<...