Await仅有效.. NodeJS

时间:2018-06-07 22:22:53

标签: javascript node.js asynchronous

我收到错误await只在异步函数中有效。当我拿出文档本身的代码时,我觉得这很奇怪。

为什么会抛出错误?

const OpTrade = require('trade-opskins-api')
const OPSKINS_API_KEY = 'key';

const opTrade = new OpTrade(OPSKINS_API_KEY);
const interface = 'user'; // item | trade | user
const method = 'GetProfile';

// const response = await opTrade.userGetProfile() 
// or
const response = await opTrade[interface + method]()

console.log(JSON.stringify(response, null, 2));

0 个答案:

没有答案