【发布时间】:2022-01-07 07:35:11
【问题描述】:
这两个promise有什么区别,一个用在参数other outisde中,哪个是首选
fetch(API_URL + "films")
.then(response => response.json())
.then(films => {
output.innerText = getFilmTitles(films);
})
.catch(error => output.innerText = ":(")
fetch(API_URL + "films")
.then(response =>
response.json()
.then(films => {
output.innerText = getFilmTitles(films);
}))
.catch(error => output.innerText = ":(")
【问题讨论】:
-
第二个语法无效。
-
@AKX 为什么语法无效?
response.json()返回一个承诺,它可以是then()'d 就可以了吗? -
@AKX 我的意思是,只有右括号。所以..有点不必要的评论
-
你刚刚错过了一个结束)。假设这是一个错字,我在答案中添加了它。
-
请使用正确的括号更正您的语法,以便我们确定您的意思。您的第二个选项没有匹配的括号。
标签: javascript async-await es6-promise