如何在javascript中实现异步功能

如何在javascript中实现异步功能,javascript,Javascript,我需要使用异步函数或承诺向api发送数据,但 下面的代码在参数列表后的同一行上抛出SyntaxError:get'(' 有人能告诉我我做错了什么吗?这是密码 async createTx() { let key = await ar.wallets.generate(); let transaction = await ar.createTransaction({ data: '<html><head><meta charset="UTF-8">&l

我需要使用异步函数或承诺向api发送数据,但

下面的代码在参数列表后的同一行上抛出
SyntaxError:get'('

有人能告诉我我做错了什么吗?这是密码

async createTx() {
let key = await ar.wallets.generate();

let transaction = await ar.createTransaction({
    data: '<html><head><meta charset="UTF-8"><title>Hello world!</title></head><body></body></html>',
}, key);

transaction.addTag('Content-Type', 'text/html');

console.log(transaction);
alert(transaction);




    return transaction;
}

// Then call it like this:
createTx().then(result => {
    alert(result);
});
async createTx(){
let key=wait ar.wallets.generate();
let transaction=wait ar.createTransaction({
数据:“你好,世界!”,
},键);
transaction.addTag('Content-Type','text/html');
console.log(事务);
警报(交易);
退货交易;
}
//那么就这样称呼它:
createTx()。然后(结果=>{
警报(结果);
});

首先,在
async
createTx
之间缺少
函数
。其次,您可能使用了一个还不能识别arrow函数的旧运行时。正如@WiktorZychla所说,将第一行重写为
异步函数createTx(){/code>,谢谢大家,它现在可以工作了