Javascript承诺-在解析之前等待.then()执行?

Javascript承诺-在解析之前等待.then()执行?,javascript,promise,Javascript,Promise,所以,我们有这样的东西: 函数thePromise(){ var thePromise=新承诺(函数(){ var数据='foo'; 控制台日志(数据); 解决(); }); 退还保证金; } thePromise()。然后(函数(){ console.log('bar'); }); console.log('foobar')只需将您的承诺链接起来: var promise=新承诺(函数(解析、拒绝){ 解析(console.log('foo')); }); var fctn=函数(){ c

所以,我们有这样的东西:

函数thePromise(){
var thePromise=新承诺(函数(){
var数据='foo';
控制台日志(数据);
解决();
});
退还保证金;
}
thePromise()。然后(函数(){
console.log('bar');
});

console.log('foobar')只需将您的承诺链接起来:

var promise=新承诺(函数(解析、拒绝){
解析(console.log('foo'));
});
var fctn=函数(){
console.log('bar');
}
promise.then(fctn).then(function(){
console.log('foobar');

});您可以执行以下操作

(fctn).then((response) => {
  //Your Logic
}
如中所述(在使用angular的情况下)

然后()返回一个承诺,以便您可以链接:

thePromise().then( function(){
   console.log('bar');
})
.then(function() { 
    console.log('foobar'); 
});

一些潜在有用的阅读:也等待
fctn
不调用该函数,并且您的初始Promise回调从不调用
resolve()
。该代码永远不会在控制台上打印“bar”。@Will Cain不幸的是,我使用的东西没有使用async/await的能力。是的,您的示例和您所说的发生了什么都不起作用。事实上,这是伪造的密码。转换成一个片段。继续并更新它的行为,使其与实际代码相匹配。不幸的是,我使用的是Tianium。或者更简洁的
new Promise(函数(resolve){resolve(console.log('foo');})。然后(函数(){console.log('bar');})。然后(函数(){console.log('foobar');})