async function getTitle(url) { let response = await fetch(url); let html = await response.text(); return html.match(/<title>([\s\S]+)<\/title>/i)[1]; } for(let i=0;i<2;i++){ let urls = `https://tc39.github.io/ecma262/` !async function(){ let result = await getTitle(urls).then(function(title){ console.log('22222',title,i) return title }) console.log(result) }() }```實(shí)際運(yùn)行結(jié)果是,同時(shí)發(fā)生了兩個(gè)請(qǐng)求,然后等待請(qǐng)求接過返回后,打印結(jié)果想期望是請(qǐng)求完第一個(gè)接口,并且成功返回后,再請(qǐng)求第二個(gè)接口請(qǐng)求
for循環(huán)中的async問題
繁星coding
2019-03-29 22:18:10