0
我在Windows上使用最新版本的NodeJS和正在此错误:/等待8.5
if(await fnA()) {
^^^
SyntaxError: Unexpected identifier
这里是我的代码:
if(await fnA()) {
console.log("1");
} else {
console.log("error at 1: ");
}
async function fnA() {
return new Promise(function (resolve, reject) {
if(await fnB()) {
console.log("A");
resolve(true);
} else {
console.log("error at A: ");
reject();
}
});
}
function fnB() {
return new Promise(function (resolve, reject) {
console.log("fnB");
setTimeout(function() {
console.log("fnB after delay");
resolve(true);
}, 3000);
});
}
我试图移动await
在if条件之外,我仍然得到相同的错误。
即刚移动的误差到下一个'await'指定: '如果(等待FNB()){' ^^^ ''' 语法错误:意外identifier' – erv
我添加异步匿名回调函数并修正了这一点。干杯! – erv