Node.js - 如何获取函数的回调函数变量?

时间:2017-10-11 13:14:29

标签: node.js callback

balance.js

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(42)

a = np.cumsum(np.random.rayleigh(150, size=(50,8)), axis=1)

fig, ax=plt.subplots()

positions=np.logspace(-0.1,2.6,8)

w = 0.1
width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)

ax.boxplot(a, positions=positions, widths=width(positions,w))
ax.set_xscale("log")
plt.show()

我有一个这个代码,然后我想从功能中获得var balance

我不知道该怎么做,我想要修复代码

我需要你的帮助

1 个答案:

答案 0 :(得分:1)

你不能,考虑使用这样的Promise:

var CoinStack = require('coinstack-sdk-js')
var accessKey = 'c7dbfacbdf1510889b38c01b8440b1';
var secretKey = '10e88e9904f29c98356fd2d12b26de';
var client = new CoinStack(accessKey, secretKey);
let balancePromise = new Promise((resolve, reject)=>{

   client.getBalance(address, function(err, balance) {
     if(err) 
        reject(err)
     else 
       resolve(balance);
   });
})

// how to get balance value
balancePromise.then((balance)=>{
  console.log('balance', balance)
}).catch((error)=>{
  console.log('error', error)
})