How to fix "Uncaught SyntaxError: Unexpected identifier" on yield
How to fix "Uncaught SyntaxError: Unexpected identifier" on yield
我想在遍历数组时使用生成器函数来调用 API 函数。
我试过使用 setTimeout,但函数没有暂停。它进行了超过 2500 次调用并导致 CORS 提取 API 错误。
function* subjectGenerator(){
subjects.forEach(subject=>{
let examyear = startYear;
while (examyear <= endYear) {
const api = createQuestionsURLApi(subject, examyear);
// this.subject = subject.toLowerCase();
getQuestionFromURL(api, subject);
console.log(subject, api);
yield examyear++;
}
});
}
我希望 yield 被接受,所以我可以使用 subjectGenerator.next() 循环。
感谢@briosheje
function* subjectGenerator(){
for(let i = 0; i < subjects.length; i++){
const subject = subjects[i];
let examyear = startYear;
while (examyear <= endYear) {
const api = createQuestionsURLApi(subject, examyear);
getQuestionFromURL(api, subject);
console.log(subject, api);
yield examyear++;
}
}
}
我想在遍历数组时使用生成器函数来调用 API 函数。
我试过使用 setTimeout,但函数没有暂停。它进行了超过 2500 次调用并导致 CORS 提取 API 错误。
function* subjectGenerator(){
subjects.forEach(subject=>{
let examyear = startYear;
while (examyear <= endYear) {
const api = createQuestionsURLApi(subject, examyear);
// this.subject = subject.toLowerCase();
getQuestionFromURL(api, subject);
console.log(subject, api);
yield examyear++;
}
});
}
我希望 yield 被接受,所以我可以使用 subjectGenerator.next() 循环。
感谢@briosheje
function* subjectGenerator(){
for(let i = 0; i < subjects.length; i++){
const subject = subjects[i];
let examyear = startYear;
while (examyear <= endYear) {
const api = createQuestionsURLApi(subject, examyear);
getQuestionFromURL(api, subject);
console.log(subject, api);
yield examyear++;
}
}
}