先看一下翻译
我们在for循环中使用了 function(){}, 或则是() => {}, 声名了函数。浏览器回报错。但不影响使用,会很不爽,所以建议使用,变量来代替 例如:
let data = await request();
const num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const request = async () => {
url = await request();
};
for (const index of num) {
setTimeout(() => {
if (!url && index <= 9) {
request();
}
}, 2000);
}
改完:
let data = await this.request();
const num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const _setTimeout = async (index) => {
if (!url && index <= 9) {
url = await this.request();
}
};
for (const index of num) {
setTimeout(() => _setTimeout(index), 2000);
}