如何从承诺中返回价值

时间:2017-12-27 11:33:54

标签: javascript promise

如何从promise中返回值。我想比较承诺的价值和我的限额余额。但我不能在我的条件下归还我的结果。

if (getBalanceByAddress(....) > 228) {
    console.log('ALL ok')
} else {
    console.log('insufficient funds')
}

getBalanceByAddress(addressFrom) {
    var _this = this;
    return _this.web3.eth.getBalance(addressFrom).then(function(result) {
        return result;
    });
}

1 个答案:

答案 0 :(得分:3)

您需要等待它:

 (async function(){ 
  if( await getBalanceByAddress() > 228){
   console.log('ALL ok');
  } else {
   console.log('insufficient funds');
  }
 })()
相关问题